Visual Studio 2015. Failed to register URL for site access is denied IIS Express. Access denied 0x80070005 - ssl

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).

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.

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.

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...

Related

process.env.PORT is undefined

I am trying to go to production on one of my node.js applications which runs ion windows server 2012. After a week of troubleshooting and reading everything I could get to online, the problem seems to be the "process.env.PORT" variable.
The symptoms are as follows:
The website works fine when:
set PORT=3510 in console
domain.com:3510/index.html in remote browser
However, when I type:
domain.com
I get a 404 - File or directory not found.
When I console.log the "process.env" object at startup of my server.js, the console.log prints an object with several properties but no "PORT" property (unless I "set PORT=3510"). Without setting the port manually prior to launching the server.js, "process.env.PORT" console.logs reports undefined.
However, If manually specify the port, the server still does not work because, according to what I read, node expects "process.env.PORT" to be a named pipe and not a number.
So the problem is very specific:
How do I set the "process.env.PORT variable" on windows 2012 server so that nodejs can work with it?
You need to set it in the web.config file. You can set a key as "PORT" with the value you need. See the below web.config file as an example...
<configuration>
<appSettings>
<add key="PORT" value="3510" />
</appSettings>
...(Other configurations here)
</configuration>

Visual Studio 2017 Enable SSL

How do you enable SSL for a project in Visual Studio 2017?
In VS15, I could select Project -> Properties -> Debug -> Enable SSL. This option is not available in VS2017. Where has it moved to?
Edit:
I've even tried editing .\vs\config\applicationhost.config to no avail:
<listenerAdapters>
<add name="http" />
<add name="https" />
</listenerAdapters>
<sites>
<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>
<site name="Filters" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="c:\Users\Ashley\documents\visual studio 2017\Projects\Filters\src\Filters" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:51107:localhost" />
<binding protocol="https" bindingInformation="*:43107:localhost" />
</bindings>
</site>
<siteDefaults>
<logFile logFormat="W3C" directory="%IIS_USER_HOME%\Logs" />
<traceFailedRequestsLogging directory="%IIS_USER_HOME%\TraceLogFiles" enabled="true" maxLogFileSizeKB="1024" />
</siteDefaults>
<applicationDefaults applicationPool="Clr4IntegratedAppPool" />
<virtualDirectoryDefaults allowSubDirConfig="true" />
</sites>
<webLimits />
Edit:
Another option I've tried, which just feels clunky, and kind of defeats the point of an IDE, is to configure Kestrel to use HTTPS. This isn't ideal since I had to export a copy of a certificate for localhost from IIS, and IIS Express still tries to load the site on a different port.
public class Program
{
public static void Main(string[] args)
{
var host = new WebHostBuilder()
.UseKestrel(options =>
options.UseHttps(new X509Certificate2("path/to/cert.pfx", "password")))
.UseContentRoot(Directory.GetCurrentDirectory())
.UseUrls("http://localhost:5100", "https://localhost:4300")
.UseIISIntegration()
.UseStartup<Startup>()
.Build();
host.Run();
}
}
Sadly, this doesn't work when run from VS17. The first time around I got a 502.2 (I think) error, now all I get is an unable to connect error in Chrome. I can run dotnet run from PowerShell and it works fine.
As a workaround, it does the trick. But it doesn't seem neat.
Ports are locked down in IIS Express so that it doesn't have to be run as Administrator...
Valid Ports are 44300 - 44399
Check out the Dev Community article
https://developercommunity.visualstudio.com/content/problem/39430/changing-port-number-in-a-web-project-does-not-imm.html
You can edit launchSettings.json, but the ssl ports must fall in this range.
This is for an Asp.Net MVC .Net Framework Project
Select your Project by highlighting it.
Then hit F4 to open its Properties pane.
Find the SSL Enabled item on list and set its value to True, and
copy SSL URL value onto your clipboard.
Whilst your Project is highlighted, hit Alt + Enter to open
the Properties dialogue - paste the copied SSL URL into the project url
under the Web menu input box.
For Visual Studio 2019 and 2017:
In Solution Explorer, right click the project > Properties
Select the Debug Tab
Check Enable SSL
In Solution Explorer right click on your website name and select "Properties Window", or simply hit F4. Under the Developer Web Server section change SSL Enabled from False to True.
For those running asp.net core 1.x in Visual Studio 2017 RC, you should be able to change the "sslPort": 0 line in the launchSettings.json file to whatever port number you would like to use for SSL. This effectively changes the bindings in the .\vs\config\applicationhost.config file mentioned in the previous answers.
This is for an Asp.Net Core 2.0:
Open up your Solution Explorer in VS2017.
Doubleclick Properties (yes, it's an object itself too, not just a folder)
Open Debug on the left side
Scroll down and select Enable SSL
If it's already enabled, open up launchSettings.json (unfold Properties) and set "sslPort" to 0, then do the steps again.
VS2017 should now ask you if you want to add an SSL certificate (something it doesn't do if you changed launchSettings.json on your own) and it'll set a port for you.
Editing the .\vs\config\applicationhost.config actually worked for me.
<site name="Filters" id="2">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="c:\Users\Ashley\documents\visual studio 2017\Projects\Filters\src\Filters" />
</application>
<bindings>
<binding protocol="http" bindingInformation="*:51107:localhost" />
**<binding protocol="https" bindingInformation="*:43107:localhost" />**
</bindings>
</site>
It does however load the app up in the browser using the non-https port by default. If you manually point your browser to the 43107 port it should work.
Edit
This worked for me a few times but stopped working. Subsequent testing revealed that whenever I would click the button to start debugging in VS 2017 RC it would remove the binding I manually added.
I fixed that by making the file read-only now it's starting with HTTPS support again.
I unfortunately had the same issue, couldn't see the "enable SSL" checkbox in the Debug tab of the Project's properties...
Finally found it! --> Set the launch on "IIS Express", then you will be able to select it ;-)
One important point you may be missing is that you have to Run Visual Studio as adminsitrator (right vlick VS icon and select 'Run as Administrator'.
I have been strugling with this SSL problem and after by running VS as adminstrator I made it work.
If you see the SSL Enabled option under the project's Properties window, but it is greyed out
Close Visual Studio
Edit the vwd.webinfo file and add the sslPort="44317" attribute to the iisExpressSettings element.
Alternatively, you can delete the vwd.webinfo file and Visual Studio will create a new one when you open the project

Visual Studio 2013: Debug using IP Address instead of LocalHost

I have a WCF REST service which debugs and works perfectly when using IISExpress and this url:
http://localhost:<portnumber>
However, for various reasons, I need it to also work with IIS Express and THIS url:
http://<ip address>:<portnumber>
When I tried originally, I got HTTP error 400: Bad request. Then I used google and ended up here: Connecting to Visual Studio debugging IIS Express server over the lan
That thread asked the EXACT same question, and the answer got me part of the way there. Following all the most excellent advice in that thread, I did the following:
Edit the IISExpress Host.config:
1: Open the %USERPROFILE%\My Documents\IISExpress\config\applicationhost.config file.
2: Changed all 17 of these lines:
<binding protocol="http" bindingInformation="*:8080:localhost" />
To look like this instead:
<binding protocol="http" bindingInformation="*:8080:*" />
(the port number varied on all 17 lines)
Visual Studio:
Closed, re-opened but ran as admin
Windows Firewall:
Added the port in question to allow incoming connections
CMD:
netsh http add urlacl url=http://*:XXXXX/ user=Everyone
Ran that command, where XXXXX is the port number.
Now, when I start debug and go to this URL:
http://<ip address>:<portnumber>
Instead of "HTTP error 400: Bad request", I now get "HTTP Error 503. The service is unavailable."
This is progress, as the browser is now at least hitting IISExpress, right? But I'm not sure at this point how to get past this 503 error. I've been searching google for that error for a while, but nothing is specific to what I'm trying to do.
Any ideas?
Figured it out. Instead of this:
<binding protocol="http" bindingInformation="*:8080:*" />
change it to this:
<binding protocol="http" bindingInformation="*:8080:" />

SSL Connection / Connection Reset with IISExpress

I'm using the new Visual Studio 2013 with IISExpress for the first time (previously used ASP.net Development server on VS2010). I'm running into issues trying to debug my project.
This is what I see in Chrome:
Unable to make a secure connection to the server. This may be a problem with the server, or it may be requiring a client authentication certificate that you don't have.
Error code: ERR_SSL_PROTOCOL_ERROR
I updated my Properies -> web file so that the Project Url uses a https URL now. However, after doing that, I now get a new error when launching:
The connection to localhost was interrupted.
Error code: ERR_CONNECTION_RESET
Thanks
I was getting ERR_CONNECTION_RESET because my Visual Studio 2013/IIS Express configured app port number was NOT in the range :44300-:44398. (I don't recall having to dismiss any warnings to get out of that range.) Changing the port number to something in this range is all I had to do to make it work.
I noticed this after reviewing the netsh http show sslcert > sslcert.txt output and something clicking with stuff I read recently about the port numbers.
Make sure to remove any previous 'localhost' certificates as those could conflict with the one generated by IIS Express. I had this same error (ERR_SSL_PROTOCOL_ERROR), and it took me many hours to finally figure it out after trying out many many "solutions". My mistake was that I had created my own 'localhost' certificate and there were two of them. I had to delete both and have IIS Express recreate it.
Here is how you can check for and remove 'localhost' certificate:
On Start, type → mmc.exe
File → Add/Remove Snap-in...
Select Certificates → Add> → Computer account → Local computer
Check under Certificates > Personal > Certificates
Make sure the localhost certificate that exist has a friendly name "IIS Express Development Certificate". If not, delete it. Or if multiple, delete all.
On Visual Studio, select project and under property tab, enable SSL=true. Save, Build and Run. IIS Express will generate a new 'localhost' certificate.
Note: If it doesn't work, try these: make sure to disable IIS Express on VS project and stopping all running app on it prior to removing 'localhost' certificate. Also, you can go to 'control panel > programs' and Repair IIS Express.
If you're using URLRewrite to force SSL connections in your web.config, it's probably rewriting your localhost address to force https. If debugging with SSL enabled isn't important to you and you're using URLRewrite, consider adding <add input="{HTTP_HOST}" pattern="localhost" negate="true" /> into your web.config file's rewrite section. It will stop the rewrite for any localhost addresses but leave it in place in a production environment.
If you're not using URLRewrite or need to debug using SSL, http://www.hanselman.com/blog/WorkingWithSSLAtDevelopmentTimeIsEasierWithIISExpress.aspx might help. It's for VS2010, but should suffice for VS2013 as well.
I am summarizing the steps that helped me in resolving this issue:
Make sure the SSL port range(used by IIS express) is between
44300-44398
During installation, IIS Express uses Http.sys to reserve ports 44300
through 44399 for SSL use. This enables standard users (without
elevated privileges) of IISExpress to configure and use SSL. For
more details on this refer here
Run the below command as administrator in Command prompt. This will output the SSL Certificate bindings in the computer. From this list, find out the certificate used by IIS express for the corresponding port :
netsh http show sslcert > sslcert.txt
Look for the below items in the sslcert.txt (in my case the IIS
express was running at port 44300)
IP:port : 0.0.0.0:44300
Certificate Hash : eb380ba6bd10fb4f597cXXXXXXXXXX
Application ID : {214124cd-d05b-4309-XXX-XXXXXXX}
Also look in the IIS express management console (RUN (Ctrl+R) -> inetmgr.exe)
and find if the corresponding certificate exists in the Server Certificates
(Click on the ServerRoot -> under section IIS () -> Open the Server
Certificates)
If your localhost by default uses a different certificate other than the one listed in Step 3, continue with the below steps
netsh http delete sslcert ipport=0.0.0.0:44300
netsh http add sslcert ipport=0.0.0.0:44300 certhash=New_Certificate_Hash_without_space appid={214124cd-d05b-4309-XXX-XXXXXXX}
The New_Certificate_Hash will be your default certificate tied-up with your localhost (That we found in step 4) or the one which you want to add as a new certificate.
P.S. Thank you for your answer uosɐſ (which helped me in resolving this issue)
The problem that I was experiencing had to do with me, at some point in time, enabling HSTS for localhost and not realizing that this would break my http://localhost:someport in IIS Express.
HSTS tells the browser (Chrome in my case) to ALWAYS request a URL using HTTPS. So therefor even though I hadnt even enabled SSL for my MVC 5 app, the browser would still try to access my site using HTTPS in the URL instead of HTTP.
The fix?
Surf to chrome://net-internals/#hsts
In the delete section, enter "localhost" and delete the record from Chrome.
None of the above options worked for me. I had to do the following:
Uninstalled IIS Express 8.0
Deleted all the configurations in my Documents directory for IIS Express
Reinstalled IIS Express 8.0
Deleted the project on my local machine and downloaded a clean version for TFS
Ran the project - it then ran over SSL and I am able to debug
I got the steps from this thread.
Hope this helps.
The issue that I had was related to #Jason Kleban's answer, but I had one small problem with my settings in the Visual Studio Properties for IIS Express.
Make sure that after you've changed the port to be in the range: 44300 to 44399, the address also starts with HTTPS
In my case, I created a self-signed certificate and had it working, except I was getting an error in the browser because the certificate was untrusted. So, I moved the cert into the Trusted Root Certification Authorities > Certificates folder in the Certificates snapin. It worked, and then I closed Visual Studio for the day.
The following day, I started my project and I received the error mentioned in the original question. The issue is that the certificate you configured IISExpress with must exist in the Personal > Certificates folder or HTTPS will stop working. Once IIS Express successfully starts, you can drag the cert back to the trusted location. It'll continue to work until you restart IIS Express.
Not wanting to fuss with dragging the cert back and forth every time, I just place a copy of the certificate in both places and now everything works fine.
I have a same problem in Visual Studio 2015. Because I use SSL binding in web.config
<rewrite>
<rules>
<rule name="HTTP to HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTPS}" pattern="off" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
And I can fix the problem with the answer of Mr.djroedger. By replacing
<add input="{HTTPS}" pattern="off" />
with
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
into my web.config, so my code is
<rewrite>
<rules>
<rule name="HTTP to HTTPS Redirect" stopProcessing="true">
<match url="(.*)" />
<conditions>
<add input="{HTTP_HOST}" pattern="localhost" negate="true" />
</conditions>
<action type="Redirect" url="https://{HTTP_HOST}/{R:1}" redirectType="Found" />
</rule>
</rules>
</rewrite>
Removing IISExpress and vs directories and using ssl port range of 44300 to 44399 (inclusive) from this article worked for me
In my case, I was getting this exact error running on port 443, and (for reasons I won't go into here) switching to a different port was not an option. In order to get IIS Express to work on port 443, I had to run this command...
C:\Program Files\IIS Express>IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:443/ -UseSelfSigned
Much thanks to Robert Muehsig for originally posting this solution here.
https://blog.codeinside.eu/2018/10/31/fix-ERR_CONNECTION_RESET-and-ERR_CERT_AUTHORITY_INVALID-with-iisexpress-and-ssl/
I was having this problem, I had configured my site for global require https in FilterConfig.cs.
public static void RegisterGlobalFilters(GlobalFilterCollection filters)
{
filters.Add(new HandleErrorAttribute());
filters.Add(new RequireHttpsAttribute());
}
I had forgotten to change the project url to https: from this tutorial http://azure.microsoft.com/en-us/documentation/articles/web-sites-dotnet-deploy-aspnet-mvc-app-membership-oauth-sql-database/ under ENABLE SSL part 4. This caused the errors you were getting.
Another problem that happened me twice:
In IIS Express's applicationhost.config the order of the bindings does matter. One binding could take precedence over your SSL binding, making it not working.
Example:
<site name="MySite007" id="1">
<application path="/" applicationPool="Clr4IntegratedAppPool">
<virtualDirectory path="/" physicalPath="C:\Users\myuser\projects\mysolutionfolder\MyProject.Service" />
</application>
<bindings>
<binding protocol="http" bindingInformation=":8081:localhost" />
<binding protocol="http" bindingInformation=":8080:" /><!-- evil binding -->
<binding protocol="https" bindingInformation="*:44327:localhost" />
</bindings>
</site>
You may have added a binding similar to the second one to be able to access your WebService from outside localhost. Because this binding listens on any adress, it seems to override the SSL binding although a different port was used.
Remove the evil binding or move it down.
For me it worked using the solution provided in the blog here.
C:\Program Files (x86)\IIS Express\IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:44387/ -UseSelfSigned
use the port that your project uses for https.
This is anecdotal as overheard from a co-worker, but allegedly this is an issue with chrome forcing https. I usually launch in firefox so i hadn't seen this problem before. Using firefox or ie worked for my co-worker.
If you need to use a port outside of the 44300-44399 range, here's a workaround:
Create a new site in IIS (not Express)
Bind HTTPS to the port you need
For SSL Certificate, choose IIS Express Development Certificate
Once the site is created, stop it, since it doesn't actually need to be running
This registers the IIS Express Development certificate with that port and is the easiest way I've found to get around the 44300-44399 range requirement.
My problem was caused by Fiddler. When Fiddler crashes it occasionally messes with your proxy settings. Simply launching Fiddler seemed to fix everything (perhaps it repairs itself somehow).
To follow on to other answers about setting the SSL port between 44300 and 44399, I was unable to change the SSL Enabled property in Visual Studio, nor set a specific SSL URL. Other answers, like repairing IIS Express did not help. The solution was to go into the .vs folder parallel to the sln file, open the config subfolder, and then edit the applicationhost.config file. Then, I added the https line manually and restarted VS.
<binding protocol="http" bindingInformation="*:24941:localhost" />
<binding protocol="https" bindingInformation="*:44301:localhost" />
The 'Digicert certificate installation checker' is often helpful in situations like this.
I was able to verify the SSL cert being attempted was the one I was expecting by comparing the serial number.
For me #Jason Kleban answer was the actual problem, but this can be a very useful utility to check your basic assertions about what certificate is being loaded.
In my case after trying everything for three days, solved by just starting Visual Studio by "Run as Administrator."
KASPERSKY ISSUE!! I'd tried everything, localhost with SSL worked if I ran VS2019 as Administrator, but the connection was lost after a while of debugging, and I had to re-run the app. The only worked for me was uninstall Kaspersky, unbelievable, days ago I'd tried to pause Kaspersky protection and it didn't solve the problem, so I had discarded antivirus issues, after days of trying solutions, I resumed antivirus matter, uninstalled Kaspersky V 21.1 ..., tried and worked, installed V 21.2 ... and it works fine also without running VS as Administrator
I had the same issue running Rider/VS, both were using IIS Express to run it. I was having the issue with Postman, Chrome, Firefox and front end application calling it.
Turns out that because my laptop was appropriated for me when i started working for this company the previous developer had clicked No when asked if he wanted to use the Developer Cert the first time he ran IIS Express.
This was fixed on Windows 10 by going to Add Remove Programs (from the new UI there is a link on the right to launch the classic application for Adding and Removing Programs) then Repair IIS 10.0 or 8 or whatever version you are running.
Then try running the application again (I did this in VS but assume that Rider would do the same) and when asked whether you would like to use the Developer Certificate you click YES.
Hours wasted on this, but all sorted after that!
I'd just rebuilt my computer. This thread gave me the clues, where I realized in the project settings>Web, the project was configured to use HTTP and the HTTP port. By updating it to HTTPS and the correct HTTPS port, everything started to work again.
In my case I'd simply forgotten I had a binding set up for (in my case) https://localhost:44300 in full IIS. You can't have both!
In my case, the localhost url was redirected to https://localhost when I was debugging. This happened from one moment to other, without changing anything. I solved this by making a hard reload to the browser. Here the link
I had similar issue where my application's swagger(running on SSL port 44319) stopped working suddenly and I got ERR_CONNECTION_RESET error.
After doing a little research, I found that port 44319 was removed from the list of allow ports for SSL connection - found using this command netsh http show sslcert > sslcert.txt.
I then had to add back port 44319 to SSL allowed ports using netsh http add sslcert ipport=0.0.0.0:44319 certhash=YOUR_CERT_HASH appid={YOUR_APP_ID}.
To find the certhash and appid, you can use output of first command. This worked for me!

How to run svcutil.exe from behind authenticating proxy

I want to run the svcutil.exe tool to access a web service on the internet. Unfortunately, whenever I try, I get a bunch of errors that include the following message:
The request failed with HTTP status 407: Proxy Authentication Required ( The ISA Server requires authorization to fulfill the request. Access to the Web Proxy filter is denied.
As I have learned from this related post (with more details here), the problem is that I am sitting behind an authenticating proxy. That post explains that I need to edit the app.config file, but I can't figure out how to do that. I think I will use the /svcutilConfig:alternate_app.config switch, but I don't know how to construct a valid .config file to pass to that switch. What is the default app.config file that svcutil.exe uses?
Well, I think I have figured out the answer to my question:
It turns out that the default .config file used by svcutil.exe is called svcutil.exe.config, and (at least for me) it lives in this folder:
C:\Program Files (x86)\Microsoft SDKs\Windows\v7.0A\bin
I decided to just edit that file directly (rather than fumble around with the /svcutilConfig switch). I needed Admin privileges to do so.
The final contents of that file looked like this:
<?xml version="1.0" encoding="utf-8"?>
<configuration>
<runtime>
<generatePublisherEvidence enabled="false" />
</runtime>
<system.net>
<defaultProxy useDefaultCredentials="true" />
</system.net>
</configuration>
(with the secret sauce buried in the <system.net> element.)
In order for this all to work, I had to start the Command Prompt as Administrator, navigate to the folder listed above, and run the svcutil.exe command from there.
Hope this helps some other poor soul who gets stuck in this mess! Thanks to #AndrewWebb for the clues that got me going!