I have REST API application created using ASP.NET Core 2.1. REST API is created by WebHostBuilder and hosted by Kestrel.
Startup.Kernel = kernel; _restApiServer = new WebHostBuilder() .UseKestrel(options => { }) .UseContentRoot(Directory.GetCurrentDirectory()) .UseIISIntegration() .UseStartup<Startup>() .UseUrls(string.Format("http://localhost:{0}", _configuration.PortNumber)) .UseSetting("https_port",_configuration.HttpsPort.ToString()) .Build(); _restApiServer.Run(); REST API is served on port 8998 by default. This REST API is started by my different application. I am able to connect to this REST API using browser and POSTMAN.
Now I would like to secure my connection to REST API. What I did is: I've added necessity configuration to force secure connection in my Startup class in Configure method:
app.UseHttpsRedirection(); And I've also executed a code for trusting dev certs:
dotnet dev-certs https --trust The case is that when I try to access the web api via browser I get and error:
localhost refused to connect. Try:
Checking the connection
Checking the proxy and the firewall
ERR_CONNECTION_REFUSED
Also when I am using POSTMAN to call some REST API methods I got and error:
Could not get any response
What am I doing wrong? Do I need to specify the certificate directly in Kestrel configuration?
