ASP. NET Core 1 Deployment HTTPS (4.5.1)

Source: Internet
Author: User
Tags creative commons attribution ssl certificate

ASP. NET Core 1 Deployment HTTPS (4.5.1)?


The page you are currently viewing is an unauthorized reprint!
If the current version of the typographical error, go to view the latest version: Http://


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.


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).


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:

Corresponds to one launchSettings.json more line:

{"  iissettings":{    "windowsauthentication":  False,    "anonymousauthentication":true,    "Iisexpress" : {      "ApplicationUrl":"http://localhost:14842/",       "Sslport":44362     }  },

It is recommended that you add this certificate to a trusted root certification authority to avoid browser errors.


Unlike Iis,kestrel, which does not have a management platform, it needs to be configured in code.


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",    "Node_modules"  ],  "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
using Microsoft.AspNet.Builder;using Microsoft.AspNet.Hosting; using Microsoft.AspNet.Server.Kestrel.Https;  using System.Security.Cryptography.X509Certificates;  using System.IO; namespace Dnx451httpsdemo{     Public class Startup    {         Public Startup(ihostingenvironment Env)        {            //Set up configuration sources.            var Builder = New Configurationbuilder()                .Addjsonfile("Appsettings.json")                .Addenvironmentvariables();            Configuration = Builder.Build();        }         Public Iconfigurationroot Configuration { Get; Set; }        //This method gets called by the runtime. Use this method to add services to the container.         Public void configureservices(iservicecollection Services)        {            //ADD framework services.            Services.Addmvc();        }        //This method gets called by the runtime. Use this method to configure the HTTP request pipeline.         Public void Configure(Iapplicationbuilder app, ihostingenvironment Env, iloggerfactory loggerfactory)        {            app.Useiisplatformhandler();            app.Usestaticfiles();            app.Usemvc(); var cretpath = Path. Combine (             New DirectoryInfo(env. MapPath ("")). Parent . FullName ,                  "localhost.pfx");                                          app. Usekestrelhttps (             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.


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.


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 (4.5.1)

Related Article

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: 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.