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

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