Reputation: 11304
I created a brand new asp.net core web api app using default template with HTTPS
configured.
public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
if (env.IsDevelopment())
{
app.UseDeveloperExceptionPage();
}
else
{
app.UseHsts();
}
app.UseHttpsRedirection();
app.UseMvc();
}
When I run the app as console
application, then https
site (https://localhost:5001/api/values) is accessible and gave API
result.
Now when I deployed this web API as Window Service
, then site http
site is accessible, but https
site (https://localhost:5001/api/values) is not accessible? Whats the reason? Thanks!
Upvotes: 0
Views: 152
Reputation: 11304
After creating a certificate
dotnet dev-certs https -ep "localhost.pfx" -p Password1 --trust
I added below code,
public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
WebHost.CreateDefaultBuilder(args)
// Configure the Url and ports to bind to
// This overrides calls to UseUrls and the ASPNETCORE_URLS environment variable, but will be
// overridden if you call UseIisIntegration() and host behind IIS/IIS Express
.UseKestrel(options =>
{
options.Listen(IPAddress.Loopback, 5000);
options.Listen(IPAddress.Loopback, 5001, listenOptions =>
{
listenOptions.UseHttps("localhost.pfx", "Password1");
});
})
And it's working even after hosting web api as window service.
Upvotes: 1