Introduction

Azure App service is an HTTP based service for hosting web applications, Rest APIs and mobile back ends, you can develop in your known language using .Net, .Net core, Java, Ruby, Node.JS, PHP and Python. Asp.net core applications run and scale with both Windows and Linux based environments. In this article you will learn more about how to create web apps using asp.net core and publish applications into Azure. 

Prerequisites

  • Download and install the latest Visual Studio 2019.
  • Create new Account / Login Azure.

Create Asp.net Core App

You can start to create an asp.net core app using visual studio. Open Visual Studio and Select to create a new project template as “Asp.net core web application”. you can select your know language, in this demo, we are selecting as “C#” language.

Azure App Service:  Publish Asp.net Core Web App

Configure new Project

Second step, Provide the project name, location, solution name and click on create

Azure App Service:  Publish Asp.net Core Web App

Application Template

Microsoft provides different types of templates for creating apps. We have to create a web application for a demo, so you need to select “Web Application” and Click on “Create”.

Azure App Service:  Publish Asp.net Core Web App

Once created the application, solution will be generated with required file as below

Azure App Service:  Publish Asp.net Core Web App

Run the Application in Local

Visual Studio used a default template so you have a working web app right now by entering a project name and selecting a few options. This is a simple auto generated project, Tap F5 to run the app in debug mode or Ctl-F5 in non-debug mode.

Visual Studio starts IIS Express and runs the app. the address bar shows localhost and port number. The localhost always points to local computer.

The default template as like below with banner image and sample content.

Azure App Service:  Publish Asp.net Core Web App

Publish Web App

publish your web app, you must first create and configure a new App Service that you can publish your app to Azure and also follow the below steps .

Step 1: Right Click on Project or Solutions

Step 2: Select “Publish” options on the right click menu.

Step3: The below windows will pop up for the first time. You can select “Azure” as a publishing platform.



Azure App Service:  Publish Asp.net Core Web App

You can select the Azure App service and operating system which you want to deploy your web app in the below window and click on next.

Azure App Service:  Publish Asp.net Core Web App

Select either create an account or Sign in to sign in to your Azure subscription. If you're already signed in, select the account you want.

Azure App Service:  Publish Asp.net Core Web App

To the right of App Service instances, click on +.

Azure App Service:  Publish Asp.net Core Web App

Select subscription, Resource group and hosting plan in the following screen


  • Subscription – Select the subscription that is listed or select a new one from the drop-down list.
  • Resource group - select New. In New resource group name, enter the resource group name and select OK.
  • Hosting Plan – Select the hosting plan and click on create

Azure App Service:  Publish Asp.net Core Web App

Once the wizard completes, successfully completed build and publish web application into Azure, you can refer and try published URL in browser

Azure App Service:  Publish Asp.net Core Web App

You can navigate to published url and verify your published website available in Azure and online

Azure App Service:  Publish Asp.net Core Web App

You can also navigate to Azure portal and select on All resource and check App service and AppService plan is hosted under your resource. You can verify and manage app service plans in azure portal.

Azure App Service:  Publish Asp.net Core Web App

Summary

In this article, you have learned about creating Web Application using Dotnet core and published applications into Azure. if you have any questions/feedback/ issues, please write them in the comment box.


Singleton
 Static Class
1
Single means single object across the application
life cycle so it application level
The static does not have any Object pointer, so the scope is at App Domain level.
2
Singleton is a pattern and not a keyword
Static is key word
3
A Singleton can implement interfaces and inherit from other classes and allow inheritance.
Static class allows only static methods 
and you cannot pass static class as parameter.
Static class cannot inherit their instance members
4
Singleton Objects stored on heap memory
Static class stored in stack memory
5
Singleton Objects can have constructor
Static class will have only static constructor ,so overloading it won’t
work
6
Singleton Objects can dispose
We can’t dispose in static class
7
Singleton Objects can clone
We can’t clone in static class

C# 6.0 New Feature



How to get C# Updated Version?
Two ways we can update C# 6.0
Updated Visual Studio into VS 2014
Or
Installing Roslyn Package in VS 2013

$ Sign :

Its simplify String indexing

Example:

var value = new Dictionary() {
// using inside the initialize
$first = "Nikhil"
}

Assign value to member

C# 5.0
 C# 6.0
Value[first] =”Nikhile”
Value. $first = “Nikhil”

Exception Filters:

Exception filter already support in Vb.net now C#.net as well start to support .Exception filter is nothing but in catch block we can specify If Condition.
IF condition is fail inside catch block statement it won’t execute.

         C# 5.0
 C# 6.0
          try
            {       }
            catch (Exception ex)
            {       }

  Try  {
     throw new Exception("Null Error");
          }
catch (Exception ex) if (ex.Message == " IndexError")
            {
                // this one will not execute.
            }
            catch (Exception ex) if (ex.Message == " Null Error ")
            {
             // this one will execute
            }

await in Catch block and finally block :

Previous version C# not support await keyword in catchblock and finally block ,Now in c# 6.0 start supporting

         C# 5.0
 C# 6.0

            try
            {
                DoSomething();
            }
            catch (Exception)
            {
             //Its not Support here
                await LogService.LogAsync(ex);
            }

            try
            {
                DoSomething();
            }
            catch (Exception)
            {
               // New feature it will support
                await LogService.LogAsync(ex);
            }

Declaration Expression:

This feature allows you to declare local variable in the middle of an expression. It is as simple as that but really destroys a pain.

         C# 5.0
 C# 6.0
Int  Qty;
Int.TryParse(txtnumber.Text, out Qty)

Int.TryParse(txtnumber.Text, Int out Qty)

Auto Property Initialize:

In C# 6.0 added new feature called auto propertyinitialize like below

public class Person
{
// You can use this feature on both
//getter only and setter / getter only properties
public string FirstName { get; set; } = "Nikhil";
public string LastName { get; } = "Jagathesh";
}

Primary constructors:

A primary constructor allows us to define a constructor for a type and capture the constructor parameters to use in initialization expressions throughout the rest of the type definition. Here’s one 

simple example:

//this is primary constructor

public Class Money(string currency, decimal amount)
{
public string Currency { get; } = currency;
public decimal Amount { get; } = amount;
}

Dictionary Initialize:

         C# 5.0
 C# 6.0
Dictionary country = new Dictionary()
            {
                { "India", "TN" },
                { "United States", "Washington" },
                { "Some Country", "Some Capital " }
            };
Dictionary country = new Dictionary()
            {
                // Look at this!
                ["Afghanistan"] = "Kabul",
                ["Iran"] = "Tehran",
                ["India"] = "Delhi"
            };

Null-Conditional Operator

This is an exception that almost always indicates a bug because the developer didn’t perform sufficient null checking before invoking a member on a (null) object.

Look below new feature very interesting

         C# 5.0
 C# 6.0
public static string Truncate(string value, int length)
{
  string result = value;
//this pain work for us
  if (value != null) // Skip empty string check for elucidation
  {
    result = value.Substring(0, Math.Min(value.Length, length));
  }
  return result;
}
public static string Truncate(string value, int length)
{         
  return value?.Substring(0, Math.Min(value.Length, length));
}





Dot - Less {}
Dynamic CSS for .Net
LESS extends CSS with dynamic behavior such as variables, mixins, operations and functions.
Download latest dot less package http://www.dotlesscss.org/ ,

Java Script:

<script language="javascript">
document.onmousedown=disableclick;
status="Right Click Disabled";
Function disableclick(e)
{
if(event.button==2)
{
alert(status);
return false;
}
}

</script>

HTML Coding:

<body oncontextmenu="return false">
...
</body>
using System.Net.Mail;
Coding:
MailMessage om = new MailMessage("suthahar@gmail.com", "jssuthahar@gmail.com");
//om.CC
// om.Bcc
om.Subject = "Welcome to Suthahar bogs";
om.Body = value;
om.IsBodyHtml = true;
om.Priority=MailPriority.High;
SmtpClient os=new SmtpClient();
os.Host = "smtp.gmail.com";
os.Credentials=new System.Net.NetworkCredential("suthaharmcpd@gmail.com","*******");
os.EnableSsl = true;
os.Send(om);
Response.Write("<script>alert('mail send')</script>");



Cascading Style Sheets cascade. This means that the styles are applied in order as they are read by the browser. The first style is applied and then the second and so on. What this means is that if a style appears at the top of a style sheet and then is changed lower down in the document, the second instance of that style will be the one applied, not the first.

 For example, in the following style sheet, the paragraph text will be black, even though the first style property applied is red:

p { color: #ff0000; }
 p { color: #000000; }

The !important rule is a way to make your CSS cascade but also have the rules you feel are most crucial always be applied. A rule that has the !important property will always be applied no matter where that rule appears in the CSS document.


 So if you wanted to make sure that a property always applied, you would add the !important property to the tag. So, to make the paragraph text always red, in the above example, you would write:

Single Property Set two Different style . you can use  !importan  ( override  style)

p { color: #ff0000 !important; }
 p { color: #000000; }
using System.Net.Mail;
using System.Net;
MailMessage mail = new MailMessage();
mail.To.Add("**@gmail.com");
mail.To.Add("**@gmail.com");
mail.From = new MailAddress("**@gmail.com");
mail.Subject = "Email using Gmail";
string Body = "Hi, this mail is to test sending mail from devenvexe" +
"using Gmail in ASP.NET";
mail.Body = Body;
mail.IsBodyHtml = true;
SmtpClient smtp = new SmtpClient();
smtp.Host = "smtp.gmail.com"; //Or Your SMTP Server Address
smtp.Credentials = new System.Net.NetworkCredential
("***@gmail.com", "******");
//Or your Smtp Email ID and Password
smtp.EnableSsl = true;
smtp.Send(mail);

Reset Controls Value using Asp.net / Javascript / Jquery

Asp.net:

Dynamicaly you have to add controls means you don't know controls id so we can find control type in particular page after we can reset the page if your using C#.net coding mean page will refersh ,or if you are using javascript /j query means page not refresh

C#.net Coding:

protected void Button1_Click(object sender, EventArgs e)
{
ResetControl(this);
}

public void ResetControl(Control Parent)
{
foreach (Control c in Parent.Controls)
{

switch (c.GetType().ToString())
{
case "System.Web.UI.WebControls.TextBox":
((TextBox)c).Text = "";
break;
case "System.Web.UI.WebControls.CheckBox":
((CheckBox)c).Checked = false;
break;
case "System.Web.UI.WebControls.RadioButton":
((RadioButton)c).Checked = false;
break;
}
}
}

Javascript:

You can add client event in button .

<script language="javascript" type='text/javascript'>
function CLSEvent()
{
for (i=0; i<document.forms[0].length; i++)
{
doc = document.forms[0].elements[i];
switch (doc.type)
{
case "text" :
doc.value = "";
break;
case "checkbox" :
doc.checked = false;
break;
case "radio" :
doc.checked = false;
break;
case "select-one" :
doc.options[doc.selectedIndex].selected = false;
break;case "select-multiple" :
while (doc.selectedIndex != -1)
{
indx = doc.selectedIndex;
doc.options[indx].selected = false;
}
doc.selected = false;
break;
default :
break;
}
}
}
</script>

JQuery:

function clear_form_elements(ele) {
$(ele).find(':input').each(function() {
switch(this.type) {
case 'password':
case 'select-multiple':
case 'select-one':
case 'text':
case 'textarea':
$(this).val('');
break;
case 'checkbox':
case 'radio':
this.checked = false;
}
});
}

Lambda Expression (=>):

A lambda expression is an unnamed method written in place of a delegate instance.

The compiler immediately converts the lambda expression to either

Delegate Instance
Unmanaged Method
Lambda Expression it introduced in C# 3.0

Below is delegate method declaration

public delegate int AddTwoNumberDel(int fvalue, int svalue);

We can use lambda expression

AddTwoNumberDel AT = (a, b) => a + b;
int result= AT(1,2);
MessageBox.Show(result.ToString());

Before that what we used Please check this url
http://jsdotnetsupport.blogspot.com/2011/08/beginner-delegate-program.html

What is Syntax in Lambda Expression?:
A lambda expression has the following form:
(parameters) => expression-or-statement-block
(a, b) => a + b; this program
(a, b) èParameter
a+b è Expression /statement block=> è Lambda Expression

You can write Following format also
(a, b) =>{ return a + b }

Func ,Action Keyword:

Lambda Expression mostly used Func and Action Keyword
Func Keyword is one of the generic Delegate

Example 1:

Func<int, int,string> Add = (fvalue, svalue) => (fvalue + svalue).ToString();

MessageBox.Show(Add(3, 5)); // outPut 8

Example 2:

Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue;
MessageBox.Show(Add(3, 5).ToString()); // outPut 8
Above program how its working ?
Func è Func is Keyword
Func<int, int,string> è first Two type is parameter ,Last type is return type
Add è Add is Method Name
(fvalue, svalue èParameter
(fvalue + svalue).ToString(); è Statement

Other feature:

You can access outer variable also

Ex:

Int value=50;
Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue+ value;
MessageBox.Show(Add(3, 5).ToString()); // outPut 58

Question ?

Int value=50;
Func<int, int, int> Add = (fvalue, svalue) => fvalue + svalue+ value;
Int value=100;
MessageBox.Show(Add(3, 5).ToString());
Int value=200;
Post your Answers ….Get Special Gift …. To Bloger…..

Action Keyword:

Action Type same like Func method but The Action type receives parameters but does not return a parameter. The Func type, however, receives parameters and also returns a result value. The difference is that an Action never returns anything, while the Func always returns something. An Action is a void-style method in the C# language

Example:


using System;
class Program
{
static void Main()
{
// Example Action instances.
// ... First example uses one parameter.
// ... Second example uses two parameters.
// ... Third example uses no parameter.
// ... None have results.
Action<int> example1 =
(int x) => MessageBox.Show("Write {0}", x);
Action<int, int> example2 =
(x, y) => MessageBox.Show ("Write {0} and {1}", x, y);
Action example3 =
() => MessageBox.Show ("Done");
// Call the anonymous methods. Or example1(1)
example1.Invoke(1);
example2.Invoke(2, 3);
example3.Invoke();
}
}

Output

Write 1
Write 2 and 3
Done

Writing Plug-in Methods with Delegates

A delegate variable is assigned a method dynamically. This is useful for writing plug-in methods. In this example, we have a utility method named Add,Sub that appliesa NumberOper . The NumberOper method has a delegateparameter,



///
/// delegate declaration
///
///
///
///
public delegate int NumberOperation(int fvalue, int svalue);
///
/// Button click event it will call NumberOper method
///
///
/// 
private void btnClick_Click(object sender, EventArgs e)
{
int a = Convert.ToInt16(txtfvalue.Text);
int b = Convert.ToInt16(txtsvalue.Text);
txtresult.Text = NumberOper(a, b, Add).ToString();//Dynamic we Assign Method name
}
///
/// Button click event it will call NumberOper method
///
///
/// 
private void btnSub_Click(object sender, EventArgs e)
{
int a = Convert.ToInt16(txtfvalue.Text);
int b = Convert.ToInt16(txtsvalue.Text);
txtresult.Text = NumberOper(a, b, Sub).ToString(); //Dynamic we Assign Method name
}
///
/// Main Method with delegate Parameter
///
/// first value
/// second value
/// Dynamic Delegate
/// call method add or sub and return result
public int NumberOper(int a, int b, NumberOperation AT)
{
return AT(a, b);
}
///
/// Add two numbers Methos
///
/// first Value
/// Second value
/// Result

public int Add(int a, int b)
{
return a + b;
}
///
/// Sub two number
///
/// first value
/// Second value
/// int value

public int Sub(int a, int b)
{
return a - b;
}
Add Two Number Delegate Program

public delegate int AddTwoNumberDel(int fvalue, int svalue);

private void btnClick_Click(object sender, EventArgs e)
{
AddTwoNumberDel AT = Addnumber; // create delegate instance
//is shorthand for
//AddTwoNumberDel AT = new AddTwoNumberDel(Addnumber);
int a = Convert.ToInt16(txtfvalue.Text);
int b = Convert.ToInt16(txtsvalue.Text);
txtresult.Text = AT(a, b).ToString(); // invoke Method
//is shorthand for
//txtresult.Text = AT.Invoke(a, b).ToString();
}

public int Addnumber(int fvalue, int svalue)
{
return fvalue + svalue;
}

Note:

Copy and past your VS Editor it will Work... Do you want sample application mail me ...
What is Delegate?
  • Its reference to method.
  • once method assign to delegate its work like method
  • delegate method used any other method
Where we will use real time?

If you want to call Function in Runtime .and to get data after you can call your function but method name you don't know design time but you know runtime during time you can use "Delegate"
Different type of Delegate:
Single cast Delegate
Multicast Delegate

Single cast Delegate Syntax:

Below are signature of single cast delegate

Access-modifier delegate result-type identifier ([parameters]);

Access-modifier è Its Access permission for delegate (like public ,private ..,)

Delegate è it's a Keyword

Result-type èthis is return type (like int,string,void)

Identifier è delegate name (user define)

Parameter è run time value passing

Ex :

Way 1:

public delegate void jsdelegate();

above example is no return type ,no parameter

Way 2:

public delegate string jsdelegatevalue(int x,int y);

above example is string is return type and x,y is parameter

above 2 way are delegate declaration



Disadvatage:

Disadvantage is that only HTTP protocol could be used.
Another disadvantage is all the service will run on the same port.

WCF Programming Model:

WCF service have three parts .Service,End Point,Hosting
Service it is a class written in a .net language which have some method.service have one or more endpoint
Endpoint means communicate with client.end point have 3 parts 'ABC':
· 'A' for Address,
· 'B' for Binding
· 'C' for Contracts.
Address(WHERE): Address specifies the info about where to find the service.
Binding(HOW): Binding specifies the info for how to interact with the service.
Contracts(What): Contracts specifies the info for how the service is implemented and what it offers.
· Windows Communication Foundation is a programming platform and runtime system for building, configuring and deploying network-distributed services.
· It is the latest service oriented technology.
· WCF is a combined features of Web Service, Remoting, MSMQ and COM

WCF Advantaged:

WCF is interoperable with other services when compared to .Net Remoting,where the client and service have to be .Net.

WCF services provide better reliability and security in compared to ASMX web services.
In WCF, there is no need to make much change in code for implementing the security model and changing the binding. Small changes in the configuration will make your requirements. 

WCF has integrated logging mechanism, changing the configuration file settings will provide this functionality.

WCF services can be debugged now in Visual Studio 2008 /2010. Wcfsvchost.exe will do it for you because service will be self hosted when you start debugging.

WCF vs WebService:

Wcf and Webservice have some difference

 
Features
Web Service
WCF
Hosting
It can be hosted in IIS
It can be hosted in IIS, windows activation service, Self-hosting, Windows service
Programming
[WebService] attribute has to be added to the class
[ServiceContraact] attribute has to be added to the class
Model
[WebMethod] attribute represents the method exposed to client
[OperationContract] attribute represents the method exposed to client
Operation
One-way, Request- Response are the different operations supported in web service
One-Way, Request-Response, Duplex are different type of operations supported in WCF
XML
System.Xml.serialization name space is used for serialization
System.Runtime.Serialization namespace is used for serialization
Encoding
XML 1.0, MTOM(Message Transmission Optimization Mechanism), DIME, Custom
XML 1.0, MTOM, Binary, Custom
Transports
Can be accessed through HTTP, TCP, Custom
Can be accessed through HTTP, TCP, Named pipes, MSMQ,P2P, Custom
Protocols
Security
Security, Reliable messaging, Transactions


Featured Post

Improving C# Performance by Using AsSpan and Avoiding Substring

During development and everyday use, Substring is often the go-to choice for string manipulation. However, there are cases where Substring c...

MSDEVBUILD - English Channel

MSDEVBUILD - Tamil Channel

Popular Posts