Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to run HTTPS with IIS Express in port number 53135

Tags:

c#

https

I am using ASP.NET core 2.0.0 and using that I have created web application to run in HTTPS.To run in HTTPS I have used the following code in my Program.cs

string directory = Directory.GetCurrentDirectory();
            string portNumber = Helper.getPortNumber(directory);
            var cert = new X509Certificate2("file1.pfx", "ccc");

            var host = new WebHostBuilder()
                .UseKestrel(cfg => cfg.UseHttps(cert))
                .UseUrls("https://localhost:53135")
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>()
                .Build();

            host.Run();

Then changed the APPURL to https://localhost:53135/. If I run the program I get the error as like below:

"An error occurred attempting to determine the process id of service.exe which is hosting your application.One or more errors occurred."

But if i give port number 44300 to 44399 no exception comes and the link gets hosted successfully.I have read in a link that to run IIS Express with SSL, port number should be in the range from 44300 to 44399.I need to run my application in all ports.Can anyone please guide me how to do that?

like image 427
Suganya Avatar asked May 29 '18 10:05

Suganya


1 Answers

You need admin access for that.

Open a command prompt with admin priviledges then execute:

netsh http show sslcert

Search for a block that has IP:Port in the range of 44300 through 44399 and copy the Certificate Hash and Application ID values. Then execute:

netsh http add sslcert ipport=0.0.0.0:53135 certhash=<HASH> appid="<APPLICATION_ID>"

Replacing the values with the hash you copied in the first step.

After this, edit your .csproj and possibly .csproj.user files to make sure your Visual Studio is going to fire up the application using the correct port, example:

<IISExpressSSLPort>53135</IISExpressSSLPort>

Sometimes you may also have to edit the .vs\config\applicationhost.config file, look for the bindings and change its port. Change it to something like:

<binding protocol="https" bindingInformation="*:53135:localhost" />

Make sure to edit the binding for the correct project.

like image 117
pca1987 Avatar answered Sep 22 '22 15:09

pca1987