Since its inception in year 2001 , lots of versions of ASP.NET have been released.The current version is 4.6.You can also call it the legacy version.So you can use it for developing new applications or moving existing ASP.NET applications to newer version.ASP.NET legacy applications can run only on Windows OS.
ASP.NET Core applications can run on different operating systems and not just windows.So you can run ASP.NET Core applications on Linux ,Windows or any other OS.
ASP.NET Core is the next generation of ASP.NET framework and is complete rewrite of ASP.NET.It is a modular framework and is distributed as NuGet packages.It can run on .NET Framework as well as the .NET Core.
The main advantage of ASP.NET Core over previous versions of ASP.NET is that ASP.NET Core is modular and lightweight.
It is cross platform and can run on Linux, Unix, or OSX. It can run outside IIS via OWIN. ASP.NET Core is open source and is suitable for building applications for the cloud.You can deploy your ASP.NET Core applications directly to Azure from Visual Studio.
Anybody can contribute to ASP.NET core here https://github.com/aspnet/home
Configuration consists of name value pairs and can be defined using different formats such as JSON,XML,variables.
ASP.NET Core unifies MVC and WebAPI in a single framework.
Create ASP.NET Core application
To create a new ASP.NET Core application in Visual Studio 2017:
- Select create new project from the files menu.In the dialog that opens select .NET Core project type on the left
2.In the next dialog select Empty project template
3.Following are the files added in the solution explorer
There are two important files in ASP.NET core application:
- Program.cs
- Startup.cs
Program.cs
It consists of public static void Main() method which is the starting point of the application.We are hosting this ASP.NET Core application in a Console application.But you can host it in different hosts such as IIS or Apache.
public class Program { public static void Main(string[] args) { BuildWebHost(args).Run(); } public static IWebHost BuildWebHost(string[] args) => WebHost.CreateDefaultBuilder(args) .UseStartup<Startup>() .Build(); }
CreateDefaultBinder
CreateDefaultBinder creates a new instance of the WebHostBuilder using the default configuration.WebHostBuilder is a class which implements IWebHostBuilder interface
Startup.cs
It defines the request pipeline of the application.
Following is a sample class
public class Startup { // This method gets called by the runtime. Use this method to add services to the container. // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940 public void ConfigureServices(IServiceCollection services) { } // This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.Run(async (context) => { await context.Response.WriteAsync("Hello World!"); }); } }
the Run() method of the IApplicationBuilder is used to set up the request pipeline.The context parameter allows you to access Request or Response.
Now if you want to use MVC in your application then you can use the following:
app.UseMvc();
Leave a Reply