0

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();
    }

enter image description here

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!

1 Answer 1

1

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.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.