ReveiwHostingASP.NET – In this tutorial, we will play with ASP.NET 5 project. To accelerate the process for ASP.NET 5 project (aka ASP.NET vNext), this post will cover some tasks that include creating, examining, modifying and running the ASP.NET 5 project. To follow along, this post requires installing Visual Studio 2015 CTP.

Creating ASP.NET 5 Project

Step 1

To create a new ASP.NET 5 application, it is necessary to think in terms of projects, not web sites. The Web Site… option as seen below is still supported in Visual Studio 2015 to support legacy site development. The specific “ASP.NET vNext” features require the Project… option. With this in mind, in Visual Studio 2015 select from the top menu bar: File –> New –> Project…

Creating ASP.NET 5 Project 1

Step 2

After selecting Project…, a new project dialogue box appears.  On the left side of the box, select the Web option under the language of preference (Visual C# used below).  From there, selectASP.NET Web Application and choose the solution/project name and file location.  This post will use ASPNET5 as the solution name, and ASPNET5Blank as the project name.

Creating ASP.NET 5 Project 2

Step 3

Another dialogue box will appear to fine tune the type of web project desired.  Choose the ASP.NET 5 Empty template as seen below.  Although you may see other options, notice each is disabled.

Creating ASP.NET 5 Project 3

Examining ASP.NET 5 Project

Step 1

Once the project has loaded in Visual Studio, Solution Explorer will reveal the following:

Examining ASP.NET 5 Project 1

Step 2

The project corresponds to the following file/folder structure:

Examining ASP.NET 5 Project 2

Step 3

The following is a brief explanation of the projects file/folder contents:

HTML help file (not required to be in project, can be discarded)
*.kprojFile for managing ASP.NET 5 projects in Visual Studio
*.kproj.userFile for managing project user options in Visual Studio
debugSettings.jsonFile used by Visual Studio for debug setting
wwwrootFolder of static files served to client. No code or ‘razor’ goes here
project.jsonFile for managing project settings
Startup.csFile for startup and configuration code

The first four items above are there for the benefit of the developer using Visual Studio. The latter three are needed for development. Let’s take a look at the initial contents of the project.json file:

As can be seen above, the file contains name/value pairs (see schema at GitHub). This new approach to managing web configurations (notice no web.config) enables simplified dependency management. Instead of adding assembly references, you now add NuGet packages as dependencies. How is this better? Instead of hard-coupling a reference to an assembly, you can now simply add the dependency by just typing it into the file above. The contents of the Startup.cs file are as follows:

Step 4

The Configure method of the Startup class is automatically called at runtime. TheIApplicationBuilder instance (with parameter name app highlighted above) provides methods to configure the app and to access the HTTP request. However, when we attempt to access this method in my project, we do not see it:

Examining ASP.NET 5 Project 3

The only methods displayed are just named Use. In the next topic, the project will be modified to enable the use of other methods off of the IApplicationBuilder instance passed in.

Modifying ASP.NET 5 Project

Step 1

In Visual Studio, open the project.json file. We are going to add a dependency to the Microsoft.AspNet.Diagnostics package which is needed to get access to the UseWelcomePage method. Under dependencies, the name of the package is provided paired with the version. It must be typed accurately. However, when doing so in Visual Studio, we get discovery and auto-completion via IntelliSense!

Modifying ASP.NET 5 Project 1

n the above screen capture, I started adding the Microsoft.AspNet.Diagnostics package. When ready to add the corresponding value for version, IntelliSense came to the rescue again!

Modifying ASP.NET 5 Project 2

Step 2

After saving the project.json file, the output window in Visual Studio reveals what happened:

Modifying ASP.NET 5 Project 3

Step 3

The Microsoft.AspNet.Diagnostics package was installed along with its dependencies. Did this modify the project.json file to show the two new packages? No. And that is good news. Why? There is no need to clutter the file with hierarchies of dependencies. When a new package is referenced, the dependencies (and their dependencies) are automatically added. When removed, all dependencies are removed too! Returning to the Startup.cs file, when we now attempt to access the UseWelcomePage method, it exists!

Modifying ASP.NET 5 Project 4

The Configure method is now updated to look as follows:

Running ASP.NET 5 Project

By default, the project will be deployed to IIS Express for testing. The classic Debug menu options still work here:

Running ASP.NET 5 Project 1

When selecting either Start Debugging [F5] or Start Without Debugging [Ctrl+F5], the app will run showing the welcome screen as seen here:

Running ASP.NET 5 Project 2

Best and Recommended ASP.NET 5 Hosting

If you are looking at creating website of your own, hosting it with ASP.NET 5 can be a great choice. While there are various companies today who offer you ASP.NET 5 hosting services, it is extremely important for you to understand and compare the features that various companies offer. To make this search easier for you, we have listed down top 3 hosting providers which you need to compare for the best and recommended ASP.NET 5 hosting.

ASP.NET 5 on Cloud Hosting Tutorial: Playing With ASP.NET 5 Project