5

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?

Suganya
  • 131
  • 2
  • 3
  • This blog has a workaround to use any port with SSL: https://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx – Oguz Ozgul May 29 '18 at 10:26
  • Thank you for your reply.I could not understand what have been mentioned in that blog since I am a fresher in all these concepts.So can you please specify in which part the workaround have been mentioned? – Suganya May 29 '18 at 10:55
  • This is for IISExpress limitation. If you want more control, use IIS, put a self signed (or even visual studio) cert on there, specify any port you want. Build / publish direct to IIS. – Piotr Kula Aug 23 '18 at 15:15

2 Answers2

7

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.

pca1987
  • 323
  • 3
  • 15
  • Did you actually get this to work. I could not get IISExpress yo work with SSL outside their default port ranges for SSL – Piotr Kula Aug 23 '18 at 15:16
  • 1
    Yes I am running IISExpress on port 60544. IISExpress limits to 44300-44399 because it pre-registers those ports during installation so you dont need Admin access if you use those. For anything outside that range you need admin access to add the certssl using netsh. https://learn.microsoft.com/en-us/iis/extensions/using-iis-express/running-iis-express-without-administrative-privileges "It automatically creates and installs a self-signed SSL server certificate in the local machine store." – pca1987 Aug 23 '18 at 18:51
  • I needed to do this because a 3rd-party I needed to redirect the browser to would only allow certain ports for the redirect back...... – Dave R Jun 05 '19 at 07:25
  • This has solved my problem after hours of stress. It seems that VS2017 configured this differently; a machine with only 2019 installed was not able to use a port I could use on another machine (I have to use this port for [reasons]). Adding the port as above has fixed my problem! @pca1987 I owe you a beer! – melodiouscode Jun 17 '19 at 15:07
1

For me it worked by changing the port to 44300.

According to this post IISExpress port for https should be something like 4443xx.

MiguelSlv
  • 14,067
  • 15
  • 102
  • 169