ASP. NET Core 1 deployment of HTTPS ASP 1 deployment HTTPS (. 4.5.1)
Tips
Updated: January 23, 2016.
In the Chinese and English articles that introduce ASP. NET Core 1.0, I did not find the reason to deploy HTTPS, but I decided to write about it, except for the temporary inability to cross the platform.
Warning
Currently ( 1.0.0-rc1-update1
) only support for the full version of DNX451,DNXCORE5 requires RC2 support. Currently, you can only run on Windows.
Specifying the runtime, deploying HTTPS also requires different configuration scenarios depending on the Web server (Iis/kestrel).
Iis
This configuration, like the traditional ASP. NET 4.6 program, requires no changes to the code, as long as the certificate is configured when the domain name is specified.
IIS Express
IIS Express is a lite version for debugging purposes and can only be accessed through a domain name localhost
. Enabling HTTPS access is simple, just a tick:
Corresponding launchsettings.json
One more line:
123456789 |
{" iissettings"{ "windowsauthentication"false"Anonymousauthentication"true "iisexpress""ApplicationUrl" "http://localhost:14842/","Sslport"}, |
It is recommended that you add this certificate to a trusted root certification authority to avoid browser errors.
Kestrel
Unlike Iis,kestrel, which does not have a management platform, it needs to be configured in code.
Tips
IIS can still be used to run even if the following changes are made, but the changes do not take effect on IIS. This code only applies to 1.0.0-rc1-final
/1.0.0-rc1-update1
In project.json
, do the following:
- Delete
dnxcore5
, keep onlydnx451
- Add Reference
Microsoft.AspNet.Server.Kestrel.Https
(only. NET 4.5.1 is supported)
- Increase HTTPS access port (in this case 44300)
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031 |
{"Version":"1.0.0-*","Compilationoptions":{"Emitentrypoint":True},"Dependencies":{"Microsoft.AspNet.IISPlatformHandler":"1.0.0-rc1-final","MICROSOFT.ASPNET.MVC":"6.0.0-rc1-final","Microsoft.AspNet.Server.Kestrel":"1.0.0-rc1-final", "Microsoft.AspNet.Server.Kestrel.Https":"1.0.0-rc1-final","Microsoft.AspNet.StaticFiles":"1.0.0-rc1-final"},"Commands": { "web" : " Microsoft.AspNet.Server.Kestrel--server.urls=http://*:8000;https://*:44300 "}, "frameworks" : { " dnx451 ": {} }, "Exclude" : [ "wwwroot" " "Publishexclude" : [ "**.user" "**.VSPSCC" ]} |
Also, in the Startup.cs
file, you need to add the following configuration: (40th, line 43 contains the path and password of the SSL certificate (sensitive information is not recommended hard-coded))
1 2 3 4 5 6 7 8 910111213141516171819202122232425262728293031323334353637383940414243444546474849 |
UsingMicrosoft.AspNet.Builder;UsingMicrosoft.AspNet.Hosting;UsingMicrosoft.AspNet.Server.Kestrel.Https;UsingSystem.Security.Cryptography.X509Certificates;UsingSystem.IO;NamespaceDnx451httpsdemo{PublicClassStartup{PublicStartup(IhostingenvironmentEnv){Set up configuration sources.VarBuilder=NewConfigurationbuilder().Addjsonfile("Appsettings.json").Addenvironmentvariables();Configuration=Builder.Build();}PublicIconfigurationrootConfiguration{Get;Set;}This method gets called by the runtime. Use this method to add services to the container.PublicvoidConfigureservices(IservicecollectionServices){ADD Framework Services.Services.Addmvc();}This method gets called by the runtime. Use this method to configure the HTTP request pipeline.PublicvoidConfigure(IapplicationbuilderApp,IhostingenvironmentEnv,IloggerfactoryLoggerfactory){App.Useiisplatformhandler();App.Usestaticfiles();App.Usemvc(); VarCretpath=Path.Combine( NewDirectoryInfo(Env.MapPath("")).Parent.FullName, "Localhost.pfx"); Appusekestrelhttps ( new X509certificate2 (cretpath "Certpassword" } //Entry point for the application. public static void main (string[] args) => Webapplication. Run<startup> (args}} |
Currently, we can access the Kestrel server through https://localhost:44300.
Summarize
On Windows, IIS and Kestrel can be used by the runtime with dnx451 and Dnxcore5;web servers. The current cross-platform DNXCORE5 does not support HTTPS (requires ASP. NET Core RC2 support), and it is certain that the code has changed greatly.
ASP. NET Core 1.0 is not the same as Microsoft said, RC can be used. There are many imperfections in the ASP, such as the short-term support for HTTP/2.
Statement
The ASP. NET Core 1 deployment of HTTPS (4.5.1) is authored by diligent children and licensed under the Creative Commons Attribution 4.0 International license.
Permission for use other than authorized by this License agreement may be obtained from HTTP://SPACE.CNBLOGS.COM/MSG/SEND/QIN-NZ.
ASP. NET Core 1 Deployment HTTPS