Back from my weekend and went to debug my web project which is an ASP.NET Core Web Api. It started giving me an error: Invalid URI: The hostname could not be parsed.
I can start a new asp.net core web api project and it debugs fine so I'm pretty sure its something with my configuration for this project. Any ideas?
James
I had the same issue. Just close VS, remove .vs folder, open project once again. Rebuild & Run. It should help.
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 do iisreset
after this change.
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.
This error indicates that your bindingInformation for the site is not in the correct format.
The value for bindingInformation consists of three parts.
ip:port:host
Here are some formats of bindings and their result:
<!-- Configures the site with a hostname of "www.test.com" on port 80 for the IP address of 192.168.1.10. -->
<binding protocol="http" bindingInformation="192.168.1.10:80:www.test.com" />
<!-- Configures the site with a hostname of "localhost" on port 80 for the IP address of 192.168.1.10. -->
<binding protocol="http" bindingInformation="192.168.1.10:80:localhost" />
<!-- Configures the site without a hostname and IP address on port 80. You'd use this setting to make your site directly accessible via any address that the system has, including the localhost address at 127.0.0.1, as well as any and all configured IP addresses. -->
<binding protocol="http" bindingInformation=":80:" />
<binding protocol="https" bindingInformation="*:443:" />
<!-- Configures HTTPS bindings for all IP addresses over port 443. -->
With all the above bindings, you can set the protocol to https to make your site accessible only through SSL.