Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS Express, ASP.NET Core - Invalid URI: The hostname could not be parsed

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

like image 267
James Scott Avatar asked Mar 14 '17 14:03

James Scott


2 Answers

Solution:

  1. Close Visual Studio
  2. Remove .vs folder

Fixed:)

like image 179
szubajak Avatar answered Oct 08 '22 02:10

szubajak


I post this answer because many people found my comment useful. Thanks to @joshcomley for poking me.

Hopefully this answer will help someone:

  1. In your solution folder find subfolder named .vs (note, this folder has a hidden attribute, so File Explorer does not show it by default)
  2. Open .vs/config/applicationhost.config file
  3. 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
  4. Inside <site element find a child element like:

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

and replace it with:

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

  1. 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.
like image 41
VeganHunter Avatar answered Oct 08 '22 01:10

VeganHunter