Basic deployment of ASP. NET Core

Source: Internet
Author: User
Tags dotnet webhost

With the launch of the. NET core release, I'm also ready to start using Microsoft's first ever cross-platform technology (I never learned or see the beta version of the technology), using VS2017 to create a new. NET Core Web application

Any choice here can be, in fact, created by the same, in the core, MVC and WEBAPI pipeline has been unified, so in the class library no longer appear in the API word (although in fact, now MVC has no one to use) class,

After the construction, it's probably long.

Ignoring Host.json, that's my own plus, open program, you can see that the Web application is essentially a console application,

Please ignore the Initconfigurationcontainer method again, this is also my own addition, the following article will talk about.

So, keep in mind that. NET core has never been called a Web application, and all of the program's entry points are exposed outside, with static methods main as the entry function, so-called ASP., which also establishes a webhost in this function to perform the listening and processing of the web. That's why ASP. NET core has nothing to do with IIS

First of all, this code in the webhost through Usestartup to the startup class is assigned to the startup class (in fact, you can not specify, Webhost will be based on some rules to find, this later), after the webhost to execute the Run method, Will go to execute startup, here, also see a method called Useiiintegration, call this method, you can let IIS act as an external Web recipient (reverse proxy), the request to the. NET Core program processing, This is also a way to deploy in Windows, but if you do not use this method of deployment, there will be no side effects.

Let's look at startup again.

There are two methods Configurationservice and configure, the system will execute Configurationservice configure, where Configurationservice is an optional method, In other words, even without this method, there will be no error,

So what do these two methods do, and here's a brief, configurationservice is used to configure the service, this method provides a iservicecollection, which is a dependency injection container, all the classes registered here, You can then automatically create instances based on the configuration, and Iservicecollection also provides some extension methods to help with the registration of some of the default services, such as the Addmvc method, which is used to register MVC and WEBAPI services that need to be used, note that Some services are middleware-required, such as this addmvc, if not called, then in configure even if the middleware (USEMVC) is registered, it will not work.

The Configure method provides the Iapplicationbuilder parameter, which we can use to register the middleware, such as the USEMVC here, the so-called middleware, is the previous version of the Owin middleware, is the same, used to intercept and process requests in the HTTP pipeline , since ASP. NET core is no longer bound to IIS, all the concepts of middleware, but no longer specifically identify the Owin.

You will find that there are several parameters in the configure, in fact, in addition to configurationservice this method parameter is fixed, configure method and the parameters of the startup constructor can be arbitrarily defined how many, The premise is that as long as the Iservicecollection container has been registered (the parameters in the startup constructor need to be registered in the webhost configureservices), this is also a strong place to rely on the injection container, and more importantly, The constructor of the middleware is the same way as the Invoke method, MVC or Webapi constructor, and MVC's view constructor.

And then look at it. After the Controller,asp.net core application is created, a valuescontroller is brought by default,

The ihostingenvironment in that constructor is the one I added, the dependency injection container will be automatically instantiated, here to pay attention to the previous version is not the same, there is no routeprefix such a feature, the route instead of it, and in the method of the property routing template, Directly in the HttpGet, HttpPost and other HTTP action features directly defined, before also said that MVC and WEBAPI have been unified, therefore, both are inherited from the controller base class, the system automatically according to the method of return type to perform different processing, Please forget the difference between MVC and WEBAPI.

Finally, to talk about deployment,. NET core deployment is divided into two kinds, a kind of portable deployment, which is the same as before, need to install the framework on the server ahead of time, using VS release is this, this way of execution, need to rely on the dotnet command to execute, You need to navigate to the execution directory to execute the command dotnet assembly.

Another way is to directly package the framework together in the program, this release is directly executable program (directly in Windows is an EXE file), this does not require the Server installation framework, in order to generate such an executable file,

Need to execute dotnet build-r target system or dotnet publish-c release-r target system, the first is to generate the debug version of the file, the second is used to generate release version of the file, want to be able to execute these two commands normally, You need to modify the project's csproj file,

In this place to write the need to generate the name of the environment, with; separate, there are many systems can be written, you can go to the Internet to check, here do not say, when the csproj file is modified, VS will automatically through NuGet to obtain the different system needs of the package, the process may be slow, when completed, the execution of the previous command, A folder named after the target system name is generated under the specified directory, which is the executable file for the target system.

As previously said, for ASP. IIS can be integrated with it as a reverse proxy, to do this, in addition to calling Useiiintegration,iis itself in the program requires the installation name Dotnetcore_ Windowshosting program, after installation, you can see the module named Aspnetcoremodule in the IIS module, which will intercept the request and forwarded to the ASP. NET Core Program processing

The next thing is no different from the normal configuration, create a new Web site, navigate to the Build folder, the only thing to note is that because IIS only acts as a reverse proxy (in fact, it can also be used as a service to handle static content, This is the same way as separating static files and Servlets in Java, so you need to select unmanaged code in the application pool

Once the system is started, you will find that there is a dotnet.exe process in the server process and you have to attach the process instead of w3wp.exe if you want to debug it as an additional process.

Basic deployment of ASP. NET Core

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.