The New ASP!

Source: Internet
Author: User
Tags classic asp sublime text what is asp xunit

The new ASP! background

The latest version of ASP. ASP. NET Core (also known as ASP. NET 5) It overturns the previous ASP.

What is ASP. NET Core?

ASP. NET Core 1.0 is an open-source, cross-platform development framework for building modern cloud-based WEB applications. It is rebuilt from the bottom up to provide a well-performing web application development framework that can be deployed on the cloud or on a local server. In addition, it makes ASP. NET applications more streamlined and modular (you can add other modules to it depending on your application needs), cross-platform (you can easily develop and deploy your application on Windows, Mac or Linux), and cloud optimization (you can deploy and debug your app on the cloud on the cloud).

Previous versions

What does this mean for us to use the old version of ASP?

If you are using an older version of ASP or you have a WebForms development background, you will realize how perfect ASP. NET Core is, and it feels like coming from the classic ASP era to the new ASP.

Now, let's explore

Below is a list of core changes to ASP. 1.0.

Cross-platform runtime

You can run the ASP. NET Core application on OSX and Linux, which is of great cross-era significance for ASP, and brings a whole new experience to the ASP. ASP. NET Core has two runtimes, which means you can choose a different run environment to deploy your app, making your app more flexible.

ASP. NET Core 1.0 is a refactoring version of ASP, which runs on the latest. It is modular, allowing developers to add the required modules to the application as plug-ins, most of which are provided as plug-ins and managed through the NuGet package. One of the benefits of this is that you can upgrade one module of your application without affecting the other modules at all, and. NET Core is a cross-platform runtime, so you can deploy your app on OSX or Linux operating systems, which is also a cloud-optimized runtime for deploying and debugging applications on the cloud; . NET core can be deployed with your application, and you can still run the ASP. NET Core app when there are multiple.

You can also create an ASP. NET Core app that runs only under Windows.

ASP. NET 4.6 is the latest release version of the full, fully-distributed Framework that allows you to leverage all of the. NET components and have backward compatibility capabilities. If you plan to migrate your app to. NET core, you need to make the right amount of changes because. NET core is limited to the full. NET Framework.

It needs to be clear that the ASP. NET 4.6 is more mature. It is now proven and now available and ready to use. ASP. NET Core 1.0 is a 1.0 release version that contains Web APIs and MVC, but it does not yet have SignalR and Web Pages. , it also does not support the VB and F # languages.

ASP. NET Core no longer relies only on visual Studio

The cross-platform of ASP. NET Core, so that it no longer relies only on Visual Studio, developers and designers can work in their favorite environment. Like Sublime Text,webstorm, this is awesome!

The new engineering solution structure

If you created an empty ASP. NET Core project using Visual Studio, you will see the following surprises. (unless you've created any projects before using ASP.)

Did you feel the surprise? The new engineering structure is completely different, and the project template is refreshed with the following new documents:

· Global.json: You can place a reference between the configuration information of the solution and the project here.

· Program.cs: This file contains the Main method of the ASP. NET Core RC2 application, which is responsible for configuring and starting the application.

· src folder: Contains all the project code that makes up your application.

· wwwroot: Your static files will be placed in this folder and they will all be available as resources directly to the client, including the HTML,CSS and JavaScript files.

· Project.json: Contains project settings. in ASP. NET core, you can manage dependencies by adding NuGet packages by using the NuGet Package management tool (NPM) or by editing this file. You can edit this file through any text editor, which will be easier if you use Visual Studio 2015, because its smart tips will help you find the right NuGet package as a subordinate. Project.json is like this.

· Startup.cs This stratup and configuration code that basically puts your ASP. NET Core, here's what the Stratup class looks like.

The Configureservices method defines the services that your application uses, and the Configure method is used to define the middleware that makes up the request pipeline.

· References: it contains. Netcoreapp a reference to the first version run time.

WebForms

Yes, it's sad that WebForms is no longer part of ASP. 5. You can continue to build Web Forms applications using VS2015 's. NET 4.6来, but you can't appreciate the new features of ASP. 5.

I have developed many years of enterprise-class Web Forms applications from small to large. I love Web Forms, and in fact I will continue to support the use of WebForms communities in various forums, such as http://forums.asp.net. But it's time for us to make progress and learn something new. This is the last time to learn ASP. Like many things in the past, you can either adapt or be eliminated.

In addition to WebForms, the. NET Core does not contain Windows Forms, WCF, WPF, Silverlight, and so on.

VB.net and F #

Currently, vb.net and F # are not supported in the current ASP. NET Core 1.0 RC2 version.

MVC Core Unified Architecture

ASP. NET Core will witness the MVC, Web API and Web Pages (which may be included) in a single schema, called ASP. Although the Web Pages and SignalR are not supported in the current release version.

In previous ASP. NET MVC, the MVC controller and the WEB API controller were different. An MVC controller uses the base class System.Web.MVC.Controller , a WEB API controller that uses the base class System.Web.Http.ApiController . In MVC Core, they are provided with a common base class, which is Microsoft.AspNetCore.Mvc.Controller .

For HTML Helpers, the merging of MVC and Web Pages is very likely. The WEB Pages programming model does not apply to the current version, so we cannot responsibly say which features are planned to be merged next. But we can predict that the traditional MVC model bindings will appear.

View components

In the previous ASP. NET MVC, the Html.action () helper method is typically used to invoke a sub-controller. ASP. NET MVC Core will use the new View components instead of parts that use Html.action ().

View components supports full async, which allows you to create asynchronous view assemblies.

The following is an example of a simple view component that will be returned as a personal introduction.

Using MICROSOFT.ASPNETCORE.MVC;Using Mvc6demo.models;Using System.Threading.Tasks;Using System.Collections.Generic;Namespace Mvc6demo.viewcomponents {PublicClass Personlistviewcomponent:viewcomponent {Public Async task<iviewcomponentresult> InvokeAsync (String status) {String viewtouse ="Default";BOOL isfiltered =False Personmodel model =New Personmodel ();if (status. ToLower (). Equals ( "registered")) {Viewtouse =  "registered"; isfiltered = true;} var p = await Getpersonasync (status, isfiltered); return View (viewtouse,p);} private task<ienumerable<person>> getpersonasync (string status, bool isfiltered) {return Task.fromresult (Getperson (status,isfiltered));} private ienumerable<person> Getperson (string status, bool isfiltered) {Personmodel model = new Personmodel (); if (isfiltered) return model. Getpersonsbystatus (status); else return model. GetAll; }}} </person>              

Here is the view Component:

Model) {          <li>@string. Format ("{0} {1}", P.firstname,p.lastname) </li>      }    

This shows how to call the View components

<div>       @await component.invokeasync ("registered"}) </div>  
NEW directive: @inject, @using, @inherits

The ASP. NET MVC Core provides a small number of new directives. Let's take a look at how to use @inject. The @inject directive allows you to inject a method from a class into your view.

This is a simple class to show some asynchronous methods.

Using System.Threading.Tasks;Using System.Linq;namespace mvc6demo.models {public class Stats { private personmodel _persons = new Personmodel (); public async task<int> Getpersoncount () {return Await Task.fromresult (_persons. Getall.count ()); } public async task<int> Getregisteredpersoncount () { return await Task.fromresult (_persons. Getall.where (o = O.status.tolower (). Equals ( "registered")). Count ()); } public async task<int> Getunregisteredpersoncount () { return await Task.fromresult (_persons. Getall.where (o = O.status.tolower (). Equals (

Now we can use @inject directives in the view to invoke those methods:

@inject MVC6Demo.Models.Stats Stats    @{      "Stats";  }    <div>  

Isn't that cool?

View my article on a detailed example of the new command for ASP. Getting Started with ASP. NET MVC Core

Tag Helpers

The other very cool thing about ASP. NET MVC Core is Tag Helpers. For the previous HTML Helpers,tag Helpers is an optional alternative syntax.

So compared to the following code:

@Using (Html.BeginForm ("Login","Account", FormMethod.Post,New {@class ="Form-horizontal", role ="Form"}) {@Html. AntiForgeryToken () in.True, "", new {@class = "Text-danger"}) < ;d IV class="Form-group" > @Html. labelfor (M = m.username, new {@class = "Col-md-2 Control-label "}) <div class=" col-md-10 "> @Html. textboxfor (M = m.username, new {@class = c15> "Form-control"}) @Html. validationmessagefor (M = m.username, "", new {@class = "Text-danger "}) </div> </div>}             

You can use this code:

<form asp-controller="Account" asp-action="Login" method="POST"class="Form-horizontal" role="Form" > in."validationsummary.modelonly" class=" Text-danger "></div> <div class=" Form-group "> <label asp-for=" UserName " class= "Col-md-2 control-label" ></label> <div class="col-md-10" > <input asp-for=  "UserName" class="col-md-2 control-label"/> <span asp-validation-for="UserName " class="Text-danger" ></span> </div> </div> </form>     
ASP. NET Core can be deployed not only on IIS

14 years ago, the ASP was basically only deployed on one server, IIS. A few years later, Visual Studio Development Web Server (also known as "Cassini") was used as a development service, but they eventually called system.web as the host layer in the middle of the application and Web server. The system.web host is highly coupled with IIS, so it can be very difficult to run on another host.

Later OWIN appeared as an interface between the application and the WEB server. Microsoft developed Katana as a OWIN implementation that can deploy ASP. SignalR and other third-party frameworks that can be used in IIS and IIS Express, Katana's self-hosted hosts and custom hosts.

ASP. NET Core does not emphasize the host, it behaves consistently on Katana and OWIN. ASP. NET Core can also be deployed in IIS, IIS Express or self-hosted in your own process. In addition, ASP. NET Core also contains a WEB server called Kestrel, which is built on LIBUV and is used primarily for IOS and Linux operating systems.

New HTTP request Pipeline

ASP. NET Core provides a more modular HTTP request pipeline, and you can add only the components you need. This pipeline no longer relies on system.web, and by reducing the overhead in the pipeline, your app performs better and tunes the HTTP protocol stack. The new pipeline is based on Katana project experience while supporting OWIN.

Dynamic Web Development

Another very cool feature in Visual Studio 2015 is the support for dynamic compilation. In the last ASP. NET, when we modified the app's backend code, we needed to recompile and run to see the changes in the page. In the new version of Visual Studio, you don't need to do these extra steps, just save your changes and refresh your browser.

This is the output after the page is refreshed:

Attribute Routing: [Controller] and [action] tag

In the past MVC and Web APIs, using routing attributes can cause some problems, especially if you are doing some code refactoring. This is because the route must be set to a string type, and when you modify the name of the controller, you must modify the string of the routing property

MVC Core provides new [controller] and [action] tags that can solve this problem. The following article highlights the use of these new tags. : ASP. NET MVC 6 Attribute Routing.

Integrated Dependency Injection (DI)

The ASP. NET Core incorporates support for dependency injection and Service Locator mode, which means you don't need to inject a framework Ninject or AUTOFAC through a third-party dependency.

Integrated Grunt, Gulp and Bower

Visual Studio 2015 has built-in support for popular open source WEB development tools. Grunt and Gulp can help you automate building WEB development workflows that you can use to compile and compress JavaScript files. Bower is a management tool for the client library, including CSS and JavaScript libraries.

Built-in Angularjs templates

AngularJs is one of the most Popular front-end frameworks for building single-page applications (SPAs). Visual Studio includes the creation of AngularJs modules, controllers, directives, and factories.

Support for GRUNTJS makes ASP. NET a good server-side framework for building client AngularJs applications. When you have completed a version, you can automatically merge and compress all AngularJs files. Check out my article on starting to use Angular and Angular2 in ASP.

· ASP. 5:jump Start to AngularJS with MVC 6 Web API

· ASP. Core:getting Started with AngularJS 2

SignalR 3

ASP. NET Core is also based on SignalR 3, which allows you to add real-time functionality to cloud-connected applications. See my previous SignalR Example: ASP. signalr:building A simple real-time Chat application

Web. config

in ASP. NET Core, the cluttered Web. config file is replaced by a new cloud-ready configuration file, which is called "Config.json". Microsoft wants developers to make it easier to deploy applications in the cloud and enable applications to automatically read the correct configuration parameters based on a particular environment.

This is the look of a new configuration file:

Since ASP. NET Core is plug-in, you need to configure the source code for the Stratup class as follows:

 Public Startup (Ihostingenvironment env) {var builder =new Configurationbuilder (). Setbasepath (env.            Contentrootpath); Builder.            Addenvironmentvariables (); Configuration = Builder.        Build ();        } public iconfigurationroot Configuration {get;} public void Configureservices (iservicecollection services) {services. Addmvc (); Services. Addtransient<mvc6demo.models.herostats> (); } public void Configure (Iapplicationbuilder app) {app. Usedeveloperexceptionpage (); App. USEMVC (M = {M.maproute (name: "Default", Template: "{controller}/{action}/{id}", defaults: new {contro Ller = "Home", action="Index"}); }); }
Xunit.net:. Net new Unit Testing tools

In previous ASP. NET MVC, the default test framework is the Visual Studio Unit test framework (sometimes called MSTest), which uses [TestClass] and [TestMethod] attributes to describe a unit test.

ASP. NET Core uses xunit.net as its unit test framework. This framework uses the [Fact] attribute instead of the [TestMethod] attribute, and also eliminates the dependency on the [TestClass] property.

Absolutely free and open source

Yes, ASP. NET Core is hosted on GitHub as an open source project and you can view the source code and download and submit your changes.

I agree that open source. NET is of great significance, it generates positive business significance and community significance, and is very thankful for the work that Microsoft has done.

The New ASP!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.