Top 10 new features in ASP.Net 5

ASP.Net vNext makes it easier to build leaner, faster, cloud-optimized Web applications, and it lets you do so on Windows, Linux, or Mac OS X

Microsoft's ASP.Net 5 -- aka ASP.Net vNext -- is the latest release of Microsoft’s popular and flexible framework for building modern Web applications. First released in 2002 as part of Microsoft .Net Framework 1.0, ASP.Net has come a long way in the past decade, but ASP.Net 5 is arguably the most significant revision of ASP.Net to date.

With version 5, ASP.Net becomes an open source framework, available on GitHub, with a cross-platform runtime in the works. That’s right, you’ll be able to build and execute ASP.Net 5 applications on Windows, Linux, or even Mac OS X. Plus, ASP.Net 5 brings all sorts of improvements that make applications easier to build, easier to configure, and easier to maintain.

In this article I will present my favorite new features in ASP.Net 5, with code examples wherever applicable. Note that these are not necessarily ordered based on priority or importance; indeed, it would be nearly impossible to rank them all.

ASP.Net 5 feature No. 1: Cross-platform runtime

ASP.Net 5 applications can be executed on either the full .Net CLR (Common Language Runtime) or the the new cross-platform .Net Core CLR runtime engine. The full .Net CLR is the default runtime engine that can provide compatibility with legacy applications. It runs only on the Windows operating system.

The .Net Core CLR is a lean, modular, and completely self-contained runtime that can be used to build lightweight and cloud-optimized Web applications. The Core CLR is cross-platform and open source, with ports for Windows, Linux, Mac OS X, and FreeBSD in the works. In short, you will now be able to build your application on one platform and execute it on another or even on multiple platforms.

ASP.Net 5 feature No. 2: Cloud-ready deployment

Thanks to the self-contained Core runtime, which can be deployed with your app, ASP.Net 5 is ready for the cloud. Diagnostics, session state, cache, and configuration will now work seamlessly both on premise and in the cloud. Further, multiple ASP.Net 5 apps can now be deployed side by side on the same host but configured and updated separately, because they no longer must share the same runtime. With ASP.Net 5 we now have a minimalistic .Net stack that is optimized for cloud and server workloads.

ASP.Net 5 feature No. 3: Unified core framework

One of the most fascinating of the new ASP.Net 5 features is the inclusion of a unified programming model for ASP.Net MVC, ASP.Net Web API, and ASP.Net Web Pages applications. Before ASP.Net 5, the MVC, Web API, and NetWeb Pages frameworks were implemented separately and hence contained certain inconsistencies and even conflicts.

The unified programming model means you can build applications that leverage MVC, Web API, and Web Pages without the need to reconcile differences in the three frameworks. You now have only one type of a controller to handle requests that are common to MVC, Web API, and Web Pages applications. In essence, you now have a single routing framework, a single model binding framework, and a one-filter pipeline.

ASP.Net 5 feature No. 4: Host agnosticism

ASP.Net is now host agnostic. It includes a new modular HTTP request pipeline that is optimized and can be hosted on any of the following platforms:

  • Internet Information Services (IIS)
  • OWIN (Open Web Interface for .Net)
  • Kestrel
  • Self-hosted in a custom process

Host agnosticism is a great new feature that not only eliminates the dependencies on the legacy System.Web namespace, but boosts application responsiveness to a considerable extent.

ASP.Net 5 applications don't talk directly to the Web server. Rather, host agnosticism is facilitated through “feature interfaces” provided by the IApplicationBuilder interface. This enables ASP.Net 5 applications to switch between hosts seamlessly.

The OWIN standard defines an interface between Web servers and Web clients or Web applications. Katana is Microsoft’s OWIN implementation that additionally incorporates some middleware components. In essence, Kestrel is a cross-platform Web server from Microsoft that can be used with ASP.Net 5.

ASP.Net 5 feature No. 5: Improved performance

The ASP.Net 5 framework incorporates an optimized, modular pipeline that allows you to plug in only the components that your application needs. This pipeline is based on OWIN standards and incorporates most of the learnings from the Katana project. This runtime is no longer dependent on the System.Web assembly, reducing the overhead involved in serving HTTP requests and hence improving application throughput.

ASP.Net 5 feature No. 6: Dynamic compilation

ASP.Net 5 provides an excellent new feature that promotes faster development. This was a much-awaited feature, and I was thrilled to see it incorporated in ASP.Net 5. Developing in ASP.Net 5 is more like developing in a dynamic language, because compilation now happens automatically in the background. You can now save changes to your source code files and see the results simply by refreshing your Web browser -- the separate compilation step necessary.

ASP.Net 5 feature No. 7: Support for dependency injection

Design patterns help you to more easily address recurring problems and complexities in your applications. One of the most popular design patterns is dependency injection, which is also known as the “inversion of control” pattern. You can use dependency injection to build loosely coupled application components that are easier to test and maintain.

The ASP.Net 5 engine provides excellent built-in support for dependency injection and service locator patterns. Previous ASP.Net frameworks such as MVC, Web API, and SignalR support dependency injection, but not in a consistent way. With ASP.Net 5, dependency injection is not only provided in the entire stack, but you have a much more consistent way of handling dependencies. You can access services in your controller, at startup, in action filters, in model binding -- anywhere in the pipeline.

ASP.Net 5 comes with a minimalistic dependency injection container built in, but the framework is designed so that you can easily swap it out for another, or build your own dependency injection container and use it. This is made possible because of the abstraction provided by the IServiceProvider interface on top of the dependency injection container implementation in the ASP.Net 5 runtime.

ASP.Net 5 feature No. 8: Tag helpers

Tag helpers are a new feature in ASP.Net 5 that enable preprocessing of HTML attributes with server-side content. In essence, tag helpers are a new way for you to enable dynamic rendering in ASP.Net. To work with tag helpers, you need to install the Microsoft.AspNet.Mvc.TagHelpers assembly using NuGet, then add it to your view as @addtaghelper "Microsoft.AspNet.Mvc.TagHelpers".

Consider the following code snippet that uses an HTML helper:

@model IDG.Models.Magazine
@using (Html.BeginForm())
       @Html.LabelFor(m => p.AuthorName, "Author Name:")
       @Html.TextBoxFor(m => p.AuthorName)
   <input type="submit" value="Create" />

You can accomplish the same using tag helpers as shown in the code snippet below:

@model IDG.Models.Magazine
@addtaghelper "Microsoft.AspNet.Mvc.TagHelpers"
<form asp-controller="Authors" asp-action="Create" method="post">
       <label asp-for="AuthorName">Author Name:</label>
       <input asp-for="AuthorName" />
   <input type="submit" value="Create" />

The tag helpers approach is clear, readable, and concise. Also, you need not explicitly add the AntiForgeryToken -- it is done implicitly and automatically by the form tag helper (unless you’ve explicitly overridden the behavior in your code).

You can also create a custom tag helper by extending the TagHelper class and overriding any one of the following methods:

public override void Process(TagHelperContext context, TagHelperOutput output)

public override void ProcessAsync(TagHelperContext context, TagHelperOutput output)

ASP.Net 5 feature No. 9: Simplified configuration

With ASP.Net 5 you no longer need to use the Web.config file for storing your configuration values. Rather, you can deploy your application in the cloud and use a Startup.cs file to have your application read the needed configuration data automatically. A typical Startup.cs file looks like this:

   public partial class Startup {
public Startup(IHostingEnvironment env)
    Configuration = new Configuration()

The above code snippet illustrates how you can set up your application to read configuration data from a JSON file. The Startup.cs file makes it easy to add or remove the configuration sources for your application.

ASP.Net 5 feature No. 10: Simpler dependency management

Managing project dependencies is made much simpler in ASP.Net 5. To add or update project dependencies, you can either use NuGet, the free and open source package manager for the Microsoft development platform, or you can modify the project.json file using any text editor. With Visual Studio 2015, you can even leverage IntelliSense to help locate the NuGet packages you need to add.

In summary, ASP.Net 5 is an open source, cross-platform, and lean framework that promotes faster development and enables you to build applications for either traditional Web servers or the cloud. It has been redesigned altogether to provide better performance and simpler configuration and deployment across the most popular OS platforms.

ASP.Net 5 provides support for dependency injection throughout the stack. It also unifies the programming model and provides many new programming aids such as dynamic compilation and tag helpers, not to mention many new project templates in Visual Studio 2015 to help you get started. ASP.Net 5 is currently in beta, but it’s not too soon to start discovering your own favorite features.

Copyright © 2015 IDG Communications, Inc.