Original link: http://www.cnblogs.com/Hai--D/p/5842842.html (very good written, recommended.) )
1.IIS Integration
If you're hosting through IIS, that's not the case, and powerful IIS can help us configure the site's domain name, port, and so on. As for how to deploy ASP.net core Web applications on IIS, this is not the point. A brief description:
Need to download net Core SDK and Server Hosting, download address https://www.microsoft.com/net/download
Install to see if the. NET Core SDK installs the successful command line dotnet info
Server host is installed successfully IIS modules and handler mappings see the following
Then set up the site, specify the files to the publishing site
Finally, you should configure the program pool and select unmanaged so that there are server host forwarding requests.
2.Linux Environment
Concrete installation will not say, but also a lot of. According to the official website instructions, that is, the installation of the. NET core running environment can be run.
Here we recommend a blog post for your own reference to deploy the ASP.net core application to production (CENTOS7)
Back to the point, how to configure URL and port parameters
1. Specify in the main method of the program
public static void Main (string[] args)
{
var host = new Webhostbuilder ()
. Useurls ("http://localhost:5001")
. Usekestrel ()
. Usecontentroot (Directory.GetCurrentDirectory ())
. Useiisintegration ()
. Usestartup<startup> ()
. Build ();
Host. Run ();
}
This approach is not flexible, even though it is not as elegant as reading by adding a configuration file. At this time, I think Microsoft will certainly not recommend such use, so continue to find.
2. Through environmental variables
See on the Internet there is a how to configure Kestrel URL in asp.net Core RC2,
Although the configuration file configuration, but it is not to other articles, do not need to read out configuration information, direct binding can be used, or paste code to see:
Hosting.json
{
"server.urls": "Http://localhost:60000;http://localhost:60001"
}
Program.cs
public static void Main (string[] args)
{
var config = new Configurationbuilder ()
. Setbasepath (Directory.GetCurrentDirectory ())
. Addjsonfile ("Hosting.json", Optional:true)
. Build ();
var host = new Webhostbuilder ()
. Usekestrel ()
. Useconfiguration (config)
. Usecontentroot (Directory.GetCurrentDirectory ())
. Useiisintegration ()
. Usestartup<startup> ()
. Build ();
Host. Run ();
}
So it can listen.
Now listening on:http://localhost:60000
Now listening on:http://localhost:60001
Isn't it amazing. Actual combat unbearable, buckle source. The best part of. NET core so far is the source code.
Through traceability, we can know that the main webhostbuilder is this class, under the Microsoft.AspNetCore.Hosting namespace.
The main method or build
<summary>///builds the required services and an <see cref= "Iwebhost"/> which hosts a web
Application.
</summary> public Iwebhost Build () {//Warn about deprecated environment variables if (environment.getenvironmentvariable ("hosting:environment")!= null) {CONSOLE.W Riteline ("The environment variable ' hosting:environment ' is obsolete and has been with ' replaced '"
); } if (Environment.getenvironmentvariable ("aspnet_env")!= null) {Console.writeli
NE ("The environment variable ' aspnet_env ' are obsolete and has been with ' replaced '"); } if (Environment.getenvironmentvariable ("Aspnetcore_server"). URLS ")!= null) {Console.WriteLine (" The Environment variable ' aspnetcore_server. ") URLS ' is obsolete and has been replaced with ' AspneTcore_urls ' ");
var hostingservices = buildhostingservices ();
var hostingcontainer = Hostingservices.buildserviceprovider ();
var host = new Webhost (hostingservices, Hostingcontainer, _options, _config); Host.
Initialize ();
return host; }
This is mainly to build a Webhost object, and then look more
The Initialize method to view the source code, we can know is ensureserver this method to create the URL address
private void Ensureserver () {if (server = = NULL) {Server = _applicationse Rvices.
Getrequiredservice<iserver> (); var addresses = Server.features? Get<iserveraddressesfeature> ()?
Addresses; if (addresses!= null &&!addresses. IsReadOnly && addresses.
Count = = 0) {var urls = _config[webhostdefaults.serverurlskey]?? _config[deprecatedserverurlskey]; if (!string. IsNullOrEmpty (URLs)) {foreach (var value in) URL. Split (new[] {'; '}, Stringsplitoptions.removeemptyentries)) {addresses.
ADD (value); } if (addresses.
Count = = 0) {//provide a default address if there aren ' t any configured. Addresses.
ADD ("http://localhost:5000"); }
}
}
}
Here we can know, originally it will from the configuration inside to read _config[webhostdefaults.serverurlskey] and _config[deprecatedserverurlskey]
The value of the Webhostdefaults.serverurlskey is a fixed value
The value of the Deprecatedserverurlskey is defined at the beginning of the Webhost object.