Creating ASP.Net 5 Empty Application

In this article we will learn how to create an ASP.NET 5 Empty Application.

Introduction

ASP.NET 5 is the next version of ASP.NET that enables developers to build using the modern framework for web and cloud scenarios. It contains the SignalR, MVC, Web API and Web Pages. ASP.NET 5 is a high-performance and modular design. ASP.NET products are delivered by the ASP.NET team in collaboration with a community of open source developers. ASP.NET is the significant redesign of ASP.NET and helps the developers to develop modern web applications.

Creating the Project

For creating ASP.NET 5 applications its necessary to think about the project. In Visual Studio 2015 select from the top menu bar and select File-> New->Project to create the project.


After selecting the project, the new project window or dialog box appears. From this box select the Web option under the language of preference. Now we will select the ASP.NET Web Application from the .NET Framework 4.5.3 and choose the project location and file location. Another dialog box will appear after clicking on the OK button.


 

Examining the Project

After the project has been loaded into Visual Studio 2015, the Solution Explorer contains the following folder.


Startup.cs

ASP.NET 5 uses the Startup.cs file for starting up and configured the code. The Startup.cs file is useful for starting up the project and web applications. It also contains the configuration code for the project.

project.json

ASP.NET 5 uses the project.json file for managing the project settings.

Let's have a look at the project.json file:

  1. {  
  2.     "webroot""wwwroot",  
  3.     "version""1.0.0-*",  
  4.     "exclude": [  
  5.         "wwwroot"  
  6.     ],  
  7.     "packExclude": [  
  8.         "**.kproj",  
  9.         "**.user",  
  10.         "**.vspscc"  
  11.     ],  
  12.     "dependencies": {  
  13.         "Microsoft.AspNet.Diagnostics""1.0.0-beta1",  
  14.         "Microsoft.AspNet.Server.IIS""1.0.0-beta1"  
  15.     },  
  16.     "frameworks" : {  
  17.         "aspnet50" : { },  
  18.         "aspnetcore50" : { }  
  19.     }  
  20. }  

As we can see in the preceding code, the file contains the name/value pairs. It is a new approach for managing web configurations (notice there is no web.config file) enabling simplified dependency management. Instead of adding assembly references, we can now add NuGet packages as dependencies. We can add the dependency by just typing the file above.

Startup.cs files are as follows:

  1. using System;  
  2. using Microsoft.AspNet.Builder;  
  3. using Microsoft.AspNet.Http;  
  4.   
  5. namespace WebApplication5  
  6. {  
  7.     public class Startup  
  8.     {  
  9.         public void Configure(IApplicationBuilder app)  
  10.         {  
  11.             // For more information on how to configure your application, visit http://go.microsoft.com/fwlink/?LinkID=398940  
  12.         }  
  13.     }  
  14. }  

The Configure method of the Startup class is automatically executed at runtime. The IApplicationBuilder instance provides a function to configure the application and to access the HTTP request. Now we use an example of a UseWelcomePage method in the article. When we attempt to access this method in the project, we don't see it.


In the configure window we saw only see the Use method. In the next modification, the project will be modified to enable the uses of other methods off of the IApplicationBuilder instance passed in.

Modifying the project

Now we will modify the project. In Visual Studio 2015 we open the project.json file. Now we will add a dependency for the Microsoft.AspNet.Diagnostics package. It is needed to get access to the UseWelcomePage method.


The Microsoft.AspNet.Diagnostics packages are installed along with its dependencies. Now the project.json file shows the two new packages.

Returning to the Startup.cs file, now when we access the UseWelcomePage method, it exists.


Now the Configure method is now updated to be as follows:

  1. public void Configure(IApplicationBuilder app)  
  2. {  
  3. app.UseWelcomePage();  
  4. }  

Running the Project

By default the application will be deployed to the IIS Express for the testing. Now we need to execute the application using the F5 key. After running the application the output window looks as in this:

I hope this article is helpful for the readers when they want to begin working with ASP.NET 5 Empty Applications.

Thanks for reading this article.