Visual Studio 2015. Failed to register URL for sit

2020-07-24 05:59发布

问题:

I enabled SSL in Visual Studio 2015 in order to implement Facebook and Google login locally.

I changed the project URL in the Web tab of the project's properties to https://localhost:44300/ and decorated the controller with the RequireHttps attribute - ref @msdn.

Everything worked fine locally.

I reverted settings to HTTP to test something else and that caused me a problem when I tried to get back to HTTPS.

I found this SO question and tried almost every suggested solution.

Error detail:

Failed to register URL "url" for site "site" application "path". Error description: Access is denied. (0x80070005).

回答1:

I had to issue this command in DOS to solve the problem in VS 2015:

netsh http add urlacl url=http://{ip_addr}:{port}/ user=everyone

Strangely this was only needed when I moved the project to a different PC. On the original PC I didn't need it.



回答2:

Turned out this very answer on the same question thread by Cayne led me to the solution.

The port change didn't work because applicationhost.config file, located in .vs folder specific for VS2015, kept bindings combo of old port for Http and Https as a default setting. No matter how many times did I change port to something else while trying with Http (only got clogged with mass of new web site bindings in the config file) as soon as I wanted to switch back to SSL it ended up with the first bindings combo. The port it complained about that can't be registered any more.

Once I deleted that first bindings combo everything was fine.

I hope this will help someone in the future.



回答3:

Go to C:\Users{username}\Documents\IISExpress\config and open the applicationhost.config file.

Search for the <sites> tag in the document. You will see some lines similar to the following.

<site name="WebSite1" id="1" serverAutoStart="true">
    <application path="/">
        <virtualDirectory path="/" physicalPath="%IIS_SITES_HOME%\WebSite1" />
    </application>
    <bindings>
        <binding protocol="http" bindingInformation="*:8080:localhost" />
    </bindings>
</site>

Replace the line <binding protocol="http" bindingInformation="*:8080:localhost" /> as follows.

<binding protocol="http" bindingInformation="*:{required_port_number}:*" />

I think you can even remove the * marks in bindingInformation.

Then restart IIS Server (remove all IIS server related operations using Task Manager and go to C:\Program Files\IIS Express folder and run iisexpress.exe: you might need to Run as Administrator).

A console will open and if all went well, following lines will be displayed.

Successfully registered URL "http://*:{required_port_number}/" for site "Website1" application "/" ...

Also check in browser whether the required URL works now.

Here's a very useful resource...