IIS Express, ASP.NET Core - Invalid URI: The hostname could not be parsed
I was having the same issue and tried other suggestions in this post, but it didn´t work. So I went to Properties of the project -> Debug -> WebServer Settings There I´ve replaced the * with localhost and that solved the issue for me. Properties capture
Jakub's answer does fix the issue because it causes Visual Studio to regenerate applicationhost.config. In my case, the error was saying that the value of the <binding>
tag could not be parsed. I had the following:
<binding protocol="http" bindingInformation="*:5000:*" />
which when regenerated looked like this:
<binding protocol="http" bindingInformation="*:5000:localhost" />
The file is found inside the ".vs" folder's "config" subfolder, and instead of deleting the whole directory, you can just fix/restore your <binding>
tag to a value that can be parsed.
Edit: per @VeganHunter's comment, *
is not a valid hostname. If you want it to bind to all hostnames just leave the host blank. Ex: *:80:
instead of *:80:*
means "All network interfaces/IPs, on port 80, for all hostnames".
Solution:
- Close Visual Studio
- Remove .vs folder
Fixed:)
I post this answer because many people found my comment useful. Thanks to @joshcomley for poking me.
Hopefully this answer will help someone:
- In your solution folder find subfolder named
.vs
(note, this folder has a hidden attribute, so File Explorer does not show it by default) - Open
.vs/config/applicationhost.config
file - Inside the file find element like
<site name="<Your_Web_Site_Name>" ....
. You can have several elements like this. You need to pick one where<Your_Web_Site_Name>
matches the name of your site - Inside
<site
element find a child element like:
<binding protocol="http" bindingInformation=":8080:localhost" />
and replace it with:
<binding protocol="http" bindingInformation=":8080:" />
- Rebuild solution and Run website
Notes:
- The port number 8080 is given as an example. You should assign the port that you actually use for the website.
- This fix works for websites hosted in IISExpress. It also allows to avoid error message like
Invalid URI: The hostname could not be parsed
. - If your website is using IIS, you may try to replace binding with this line:
<binding protocol="http" bindingInformation="*:8080:*" />
. And doiisreset
after this change.