I have a project based on asp.net core MVC; I want to use an SSL certificate for using https, but when running my project, it didn't show https address. I can't use IIS in my windows server.but in windows 10 everything is ok.
I'm trying install SSL certificate in windows server for using https in my project.
public static IWebHost BuildWebHost(string[] args)
{
var host = "0.0.0.0";
var http_port = 40000;
var https_port = 40001;
if (args.Length > 0) host = args[0].Trim();
if (args.Length > 1) http_port = Convert.ToInt32(args[1].Trim());
if (args.Length > 2) https_port = Convert.ToInt32(args[2].Trim());
return
WebHost.CreateDefaultBuilder(args)
.UseStartup<Startup>()
//
.UseKestrel(options =>
{
options.Limits.MaxRequestBodySize = null;
options.Limits.MaxRequestBufferSize = null;
options.Limits.MaxRequestHeaderCount = 1000;
options.Limits.MaxRequestHeadersTotalSize = 256 * 1024;
options.Listen(IPAddress.Parse(host), http_port);
using (var store = new X509Store(StoreName.My))
{
store.Open(OpenFlags.ReadOnly);
var certs = store.Certificates.Find(X509FindType.FindBySubjectName, "localhost", false);
if (certs.Count > 0)
{
var certificate = certs[0];
options.Listen(IPAddress.Parse(host), https_port, listenOptions =>
{
listenOptions.UseHttps(certificate);
});
}
}
}).Build();
}
I expect the output see https://0.0.0.0:40001, but in windows server I only have http://0.0.0.0:40000.
image of Windows server Windows server
image of Windows 10: Windows 10
If I understand things correctly, you are having a hard time using SSL in you development environment. I suggest you look here Enforce HTTPS in ASP.NET CORE. At this point on the page, Trust the ASP.NET Core Development Certificates..,you'll probably find the solution to your problem.