ASP.NET 5 ,codenamed ASP.NET vNEXT is the next version of ASP.NET.It includes significant changes from the prvious versions of ASP.NET.This is because ASP.NET 5 has been redesigned for the web applications of today.Some of the important features of ASP.NET 5 are
- It has a modular pipeline over which we have a total control unlike the fixed pipeline in the previous versions.
- ASP.NET 5 applications can run as easily on cloud as it can on premise
- Applications can run on different platforms ,such as Linux, not only on windows
- It is shipped as a set of nuget packages
We can create ASP.NET 5 applications using visual studio 2015 preview.
Creating asp.net 5 mvc application in visual studio
To create an MVC 6 application we use the new project menu option.We get the below dialog on selecting new project option. Select the web application template .
Next we select the ASP.NET starter web template and click ok.
A new Web application project is created with the following project structure
These are new files introduced in ASP.NET 5.
- bower.json takes care of fetching and installing the packages used by our application
- config.json In the previous versions we had web.config.Now we have the config file which contain the configuration values.It can be in one of different formats ini,xml and json.
- project.json contains the project dependencies as nuget packages.
- startup.cs the application pipeline is configured in the startup class in this file
- If look at the contents of startup.cs file it contains the startup class which is defined as
public class Startup { public void Configure(IApplicationBuilder app) { var configuration = new Configuration() .AddJsonFile("config.json") .AddEnvironmentVariables(); app.UseServices(services => { services.AddMvc(configuration); }); app.UseMvc(routes => { routes.MapRoute("areaRoute", "{area:exists}/{controller}/{action}", new { controller = "Home", action = "Index" }); routes.MapRoute("ActionAsMethod", "{controller}/{action}", defaults: new { controller = "Home", action = "Index" }); });
Two of the important methods used in the above code are
- app.UseServices() adds the services to the service collection.To add service for mvc we call AddMvc(configuration)
- app.UseMvc() this is an extension method which defines the routes used in the application using the IRouteBuilder interface.
These are extension methods defined on the IApplicationBuilder interface.In the aboce code we have added two routes to the IRouteBuilder.
If we now run the application we get the below page using the default routes defined above.
So as we can see above the configure method gives us complete control over the components we want to add to the pipeline.
Leave a Reply