IIS Express, ASP.NET Core - Invalid URI: host name cannot be parsed

Back from my weekend and set off to debug my web project, which is ASP.NET Core Web Api. This started giving me an error: Invalid URI: hostname could not be parsed.

I can start a new asp.net core web api project and it is fine debugging, so I am sure that this is something with my configuration for this project. Any ideas?

James

+7
source share
5 answers

I had the same problem. Just close VS, delete the .vs folder, open the project again. Rebuild and run. This should help.

+13
source

I am posting this answer because many people found my comment helpful. Thanks @joshcomley for poking me.

Hope this answer helps someone:

  1. In the folder of your solution, find the subfolder named .vs (note that this folder has a hidden attribute, so Explorer does not show it by default)
  2. Open .vs/config/applicationhost.config
  3. Inside the file, find an element like <site name="<Your_Web_Site_Name>".... You may have several such elements. You need to choose the one where <Your_Web_Site_Name> matches the name of your site
  4. Inside the <site element, find the child element, for example:

<binding protocol="http" bindingInformation=":8080:localhost"/>

and replace it with:

<binding protocol="http" bindingInformation=":8080:"/>

  1. Rebuild the solution and launch the site

Notes:

  • Port number 8080 is an example. You must designate the port that you are actually using for the website.
  • This hotfix works for websites hosted by IISExpress . It also avoids error messages such as Invalid URI: The hostname could not be parsed .
  • If IIS is used on your website, you can try replacing the binding with the following line: <binding protocol="http" bindingInformation="*:8080:*"/> . And do iisreset after this change.
+8
source

Jakub's answer really solves the problem because it calls Visual Studio to regenerate applicationhost.config. In my case, the error said that the value of the <binding> could not be parsed. I had the following: <binding protocol="http" bindingInformation="*:5000:*" /> which, when regenerating, looked like this: <binding protocol="http" bindingInformation="*:5000:localhost" /> file is in the β€œconfig” subfolder of the β€œ.vs” folder, and instead of deleting the entire directory, you can simply fix / restore the <binding> to a value that can be analyzed.

Edit : for @VeganHunter comment , * not a valid hostname. If you want it to bind to all host names, just leave the host empty. Example: *:80: instead of *:80:* means "All network interfaces / IP addresses on port 80 for all host names."

+4
source

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 connections, you can install the https protocol to make your site accessible only through SSL.

+1
source

I had a similar problem and starting Visual Studio in admin mode solved this problem for me.

0
source

Source: https://habr.com/ru/post/1265439/


All Articles