This morning I made some changes to a project for a future post. Minor stuff and nothing that should have caused issues, but when I tried to run the project I got the following error from Kestrel.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to https://localhost:5001 on the IPv4 loopback interface: ‘An attempt was made to access a socket in a way forbidden by its access permissions.’.
warn: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to bind to https://localhost:5001 on the IPv6 loopback interface: ‘An attempt was made to access a socket in a way forbidden by its access permissions.’.
crit: Microsoft.AspNetCore.Server.Kestrel[0]
Unable to start Kestrel.
System.IO.IOException: Failed to bind to address https://localhost:5001.
I had limited time so I switched the project over to launch using IIS Express and hit run, but this resulted in the following error.
HTTP Error 500.35 – ANCM Multiple In-Process Applications in same Process
Switching back to Kestrel and changing the port number in the applicationUrl setting in the launchSettings.json file fixed the issue. Later I came back to the application and tried to track down what was using the same ports and couldn’t find anything. After a reboot, all worked fine with Kestrel and the original port numbers.
For the IIS Express error, I ended up having to delete the .vs directory which can be found in the same directory as your solution file if you are using Visual Studio 2019. Thanks to stackoverflow for this fix.
Wrapping Up
Not the post I set out to write this week, but hopefully this will save someone some searching in the future, more than likely myself.
Also published on Medium.
Because IIS server still running with same port. Please stop it and run again
Saved me just now.. Thanks!
Thank you
net stop winnat
was the only thing that worked for me (you can even restart it again and it should be fine).
Awesome!! Thanks, that was the perfect solution for me!
Many thanks. It saved me
I was able to get it to work by changing this setting in the appsettings.json file. It changes the port on which the application runs. It worked very well for me.
“Kestrel”: {
“EndPoints”: {
“Https”: {
“Url”: “https://localhost:4300”
}
}
}
Credit to this site
https://syntaxfix.com/question/2588/how-to-change-the-port-number-for-asp-net-core-app