1

I have a web application that behaves differently depending on the hostname. To test it on my local PC, I will then need to arrange for IISExpress to run the web application using a specific name that I provide in Project -> Properties -> Debug, such as http://mywebsite:58981/.

enter image description here

But when start debugging, a pop up message "Unable to connect to web server 'IIS Express'" pops up. And Windows 10 activity center alerted me of a message and upon clicking it, I received this pop-up from IIS Express:

enter image description here

I tried what other users suggested such as deleting the .vs folder containing the applicationhost.config and restarted the solution, but it still doesn't work. I even made sure that IIS Express doesn't have anything else running:

enter image description here

But if I changed the App URL back to http://localhost:58981/, deleted the .vs folder, and open the solution, I can debug as usual.

So my question is: how do I change the URL from localhost to something else? I'm running Visual Studio 2019 and my Windows 10 is 1903 edition.

1
  • 1
    Publish the web app to IIS and then you can test it out or debug on IIS. Microsoft designs VS/IIS Express integration to work only for localhost for a reason, which you probably should not challenge. Of course, there can be third party options. More background can be found in blog.lextudio.com/… Commented May 8, 2019 at 3:38

1 Answer 1

5

The first advise is run Visual Studio as Administrator.

Modify the IIS Express configuration files , go to edit file :

\{project folder}\.vs\{yourWebApplicationName}\config\applicationhost.config

You will find something like this(find with your application name):

<site name="WebApplication3" id="2">
    <application path="/" applicationPool="WebApplication3 AppPool">
      <virtualDirectory path="/" physicalPath="C:\Users\Administrator\source\repos\WebApplication3\WebApplication3" />
    </application>
    <bindings>
      <binding protocol="http" bindingInformation="*:53717:localhost" />
      <binding protocol="https" bindingInformation="*:44325:localhost" />

    </bindings>
</site>

Add in <bindings>, add another row with your own IP, port number:

<binding protocol="http" bindingInformation="*:53717:mywebsite" />

Go to C:\Windows\System32\drivers\etc edit the hosts file (copy to another place ,edit and copy back):

# localhost name resolution is handled within DNS itself.
    127.0.0.1       mywebsite
#   ::1             localhost

Then you could use http://mywebsite:53707 to debug your application , you may comment out app.UseHttpsRedirection(); in Configure to handle HTTP request .

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks! Running as administrator does the trick. And manually adding additional binding solution is elegant and I just need to do it once, so once it's done, I can switch between hostname without restarting the debugging session.
running vs as admin is OK? i remember reading somewhere that running vs as admin can cause some trouble but i don't remember what was the trouble tbh.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.