ASP.NET 5 Overview

Original author: Tom FitzMacken
  • Transfer
ASP.NET 5 brings significant changes to the ASP.NET platform. This article explores new ASP.NET 5 concepts and explains how they will help you develop modern web applications.

Introduction to ASP.NET 5.


ASP.NET 5 is a stack devoid of all redundant .NET for building modern web applications. We built it from scratch to provide an optimized platform for developing applications that will be deployed in the cloud or run on their own servers. To support flexibility in building solutions, this platform consists of modular components with minimal overhead.
ASP.NET 5 includes the following features:

  • New Flexible and Cross-Platform Runtime
  • New Modular Pipeline for HTTP Requests
  • Ready to use cloud configuration
  • A unified programming model that combines MVC, Web API, and Web Pages
  • The ability to see changes without re-building the project
  • Using multiple versions of the .NET Framework side by side
  • Possibility of self-hosting or hosting on IIS
  • New Tools in Visual Studio 2015
  • GitHub Open Source

The changes we made for ASP.NET 5 were based on customer requests and feedback. These changes simplify development, hosting and maintenance, and focus on modern web applications.

Your legacy applications will run on the new version of ASP.NET without any modifications. But to take advantage of the new features in ASP.NET 5, you must port the existing code to a new framework. You will find many similarities between ASP.NET 5 and earlier versions of ASP.NET, so porting the code is to fix specific problem areas, rather than rewriting the entire application.

This article presents the direction of ASP.NET 5 and explains the changes.

Download Visual Studio 2015 Preview


You can already start working with ASP.NET 5 by downloading Visual Studio 2015 Preview. For more information on what is included in this release, read Visual Studio 2015 Preview .

In this article





Why was ASP.NET redesigned?


The need for a flexible cross-platform runtime

In the past, the .NET Framework has been used as a single, comprehensive installation. In each new .NET release, new features were added, but old ones were rarely removed, so the size of the framework was constantly growing. This approach ensures that a machine with .NET installed can support any type of .NET application, but this means that each application has a dependency on functionality that is not actually used.

If a critical update is necessary for one of the technologies in .NET, you will receive a notification that an important update is available, even if this part of .NET is not used by your applications. You must decide whether to install this update and interrupt the application or ignore the updates, in the hope that the update is not really needed.

ASP.NET 5 gives you more flexibility by being able to work in three variants of the runtime environment:
  1. Full .NET CLR
    Full .NET CLR is the default runtime for projects in Visual Studio. It provides a complete set of APIs and is the best choice for backward compatibility.
  2. Core CLR (cloud-optimized runtime)
    Core CLR is a runtime environment for ASP.NET 5 projects. It is free from all unnecessary and is completely modular. This CLR has been redone for the component model, now it is possible to include only those functions that are needed in your application. You simply add components as NuGet packages. As a result, your application depends only on the necessary functions. With this approach to developing the runtime environment, we can deliver component updates faster because each component is updated on its own schedule. The Core CLR takes up about 11 megabytes instead of about 200 megabytes for the full version of the .NET CLR. The Core CLR can be deployed directly with your application, and various versions of the Core CLR can work side by side (both of which are described in more detail below).
  3. Cross-platform CLR
    We will release a cross-platform runtime for Linux and Mac OS X. This runtime allows you to develop and run .NET applications on Mac and Linux devices. We work closely with the Mono community. Prior to release, you can use Mono CLR for cross-platform development. For more information, see ASP.NET vNext Application Development on Mac ( translator's note : the August article is available via the link, there is a post on Habré describing the current state of affairs).


By default, new Visual Studio projects will use the Full .NET CLR. You can specify the Core CLR in the configuration properties of your project.

image

Hosting anywhere

ASP.NET 5 allows you to host your application on IIS or in self-hosting mode. When you use the Core CLR, you can deploy the application with all the dependencies collected in the deployment package. Thus, the application and its dependencies are completely autonomous and no longer depend on the installation of .NET in the system. The application can run on any type of device or hosting platform.

This new opportunity gives a lot of freedom. We still recommend IIS as the best option for hosting, but you can use a different hosting platform if necessary. Your hosting settings no longer determine which framework to use for development and vice versa.

An example of hosting an application outside of IIS: Creating a web API in MVC 6 .

Use different versions of .NET side by side

When applications on a server depend on a single, system-wide installation of the .NET Framework, all applications run on the same version of .NET. This situation creates some concern when considering upgrading to a new version of the .NET Framework. You might want some of your applications to use the latest version of .NET, but you are not sure that all of your old applications will work properly with the new version.

Fortunately, ASP.NET 5 fixes this problem. You can define dependencies within the deployment package and specify the .NET version for each application. You get all the benefits of the latest version for some applications and just keep using the old version for the rest. All of these different versions work side by side without any problems. To run applications with different versions side by side, you must select the target core CLR for them.

Simplify dependency management

ASP.NET 5 introduces a new, easy way to manage dependencies in your projects. You no longer need to add assembly references to the project; instead, you manage dependencies by referencing NuGet packages. You can add NuGet packages using the NuGet package manager or you can edit the JSON file (project.json), which lists the NuGet packages and versions used in your project. To add other dependencies, you simply write the name and version number of the NuGet package in the project.json file.

image

In Visual Studio 2015, IntelliSense helps you find affordable NuGet packages.

image

The project.json file includes only NuGet packages that were directly added to the project. If you add a NuGet package that depends on other packages, these secondary dependencies are loaded but not listed in the project.json file. This approach allows you to keep the project.json file uncluttered and easy to manage. If you remove the NuGet package from project.json, the secondary dependencies are also deleted if there are no other packages that need them.

Thanks to the JSON format, dependency management is easy even if Visual Studio is not installed. You can open the project.json file in any text editor and make changes, for example, update the dependencies of the application deployed in the cloud.

Eliminate duplication in MVC, Web API, and Web Pages

In the past, MVC, Web API, and Web Pages contained various implementations of similar functionality. For example, MVC and the Web API provide routing, but the MVC routing classes are located in the System.Web.Mvc.Routing namespace, and similar Web API classes are located in System.Web.Http.Routing. Or, Web Pages and MVC both use Razor syntax, but some NuGet packages are compatible with only one or another implementation.

In ASP.NET 5, MVC, Web API, and web pages will be merged into a single framework called MVC 6. This merge removes duplication from the framework and makes application development easier. You no longer need to write slightly different code depending on whether you are using MVC, Web API or Web Pages.

In this preview version, MVC and Web API were combined into MVC 6.Web Pages will be added in MVC 6 in a later version.

Improving HTTP Performance

ASP.NET 5 introduces a new software pipeline for HTTP requests, which eliminates all unnecessary. This conveyor is modular, you can add only those components that are needed. The application will have greater bandwidth by reducing overhead. The new pipeline also supports Owin .

Cloud Ready

When you create a new ASP.NET 5 project, this project is structured for easy deployment in the cloud. Visual Studio 2015 provides a new environment configuration system that replaces the Web.config file. The new system allows you to query named values ​​from various sources (for example, JSON, XML, or environment variables). You specify values ​​for each environment, and after deployment, your application simply reads the correct values.

We also provide diagnostics and tracing tools that make it easy to detect application problems in the cloud.

Dependency Injection Integration

Dependency injection is built into ASP.NET 5. You can use your IoC container to register dependencies. Injection dependency makes it easy to provide the right services for your environment of use. For more information, see Dependecy Injection in ASP.NET vNext .


Open source and make transparent

All code for ASP.NET 5 is available on GitHub . Not only is the code available, we use the GitHub repositories for our entire development. You can see exactly what changes were made and when they were made. You can download the code and provide changes.

By developing ASP.NET 5 on GitHub, we make it easier to understand the code and our intended development. You can offer your edits or develop a custom implementation of ASP.NET.

Provide a flexible development environment

Visual Studio 2015 offers a lightweight approach to developing ASP.NET applications. You simply make changes to the code, save the changes and refresh the page in the browser. You will see browser changes without re-building the project.

image

You can change the code of the web project or the code of the class library referenced by the project. You can run a project (CTRL + F5) rather than being in debug mode to see the changes.

Visual Studio uses the Roslyn compiler for dynamic compilation. The full power of the compiled framework is still available to you, but the development creates the feeling of using an interpreted language.

Each function in the Visual Studio GUI corresponds to a command line operation. You can easily switch between using the interface and writing scripts on the command line.

Finally, you can use other code editors for ASP.NET 5 projects.

What about web forms?


You can continue to develop your application using Web Forms and be fully confident that Web Forms are an integral part of the .NET web development platform. We remain focused on adding new features to Web Forms so that your development experience is consistent with current web practices.

Web Forms 4.6 includes the following new features:
  • HTTP 2
  • Asynchronous Binding Model
  • Roslyn CodeDOM Compilers

Existing Web Forms applications will continue to run unchanged on IIS with .NET 4.6. You cannot use Web Forms applications with the Core CLR.

The link is available video about new features in Web Forms 4.6. For a description of the many changes for Web Forms in Visual Studio 2013 Update 2, see Improvements to ASP.NET Web Forms.

What about old apps?


Perhaps you are worried that with so many changes in ASP.NET 5, you will now need to rewrite all your applications? Do not worry. Applications built on earlier versions of ASP.NET will continue to work with the new .NET Framework. You do not need to update or port these applications unless you need new ASP.NET 5 features.

For example, your applications that currently use Web Forms, MVC 5, Web API 2, SignalR 2, Web Pages 3, or Entity Framework 6 fully supported in the new framework unchanged. However, you must use the full .NET CLR to run older applications, because only in this CLR is full compatibility with earlier versions ensured.

The core CLR has a somewhat limited API. To use the Core CLR, an application must use only the types and members that are available in this runtime.

To make sure your application can run in the Core CLR runtime, use the Portability Analyzer API . This tool tells you which platforms your application can run on and which dependencies block the launch of the application on other platforms. This helps you understand the extent of the changes needed and offers new types or members to replace unsupported ones.

MVC 6 and SignalR 3 applications use the new HTTP pipeline, so they are not compatible with applications that use System.Web. To upgrade an existing application to MVC 6 or SignalR 3, you must create a new project in Visual Studio 2015, and then transfer the code to the new project. When porting, then you need to change the unsupported code.

Also popular now: