localhost refused to connect Error in visual studio
Solution 1:
I had a similar issue. Try this and it should work
Go to your project folder and open the
.vs
folder (keep your check hidden item-box checked as this folder may be hidden sometimes)In the
.vs
folder open theconfig
folderSee that
applicationhost.config
file there? Delete that thing. (Do not worry it will regenerate automatically once you recompile the project.)
Solution 2:
Usually on local machine we are getting errors like This site can't be reached localhost refused to connect
because we have self signed certificate configuration broken for local IIS Express. Sometimes it happens when you change URLs in launchSettings.json
or never configured self signed certificates on this machine at all.
To fix self-signed certificate on the local machine you need to:
- Delete .vs folder (requires to close Visual Studio 2017)
-
Run these commands in
cmd
As Administrator
:cd "C:\Program Files (x86)\IIS Express"
IisExpressAdminCmd.exe setupsslUrl -url:https://localhost:12345/ -UseSelfSigned
Make sure you run VS2017
As Administrator
and check if the issue addressed
Note: https://localhost:12345/
is what is in your launchSettings.json
for HTTPS
Solution 3:
Changing port number has resolved the issue