Working With Visual Studio and IIS Express Apps Locally

Applies to CrossBrowserTesting SaaS, last modified on January 10, 2023

This page relates to the legacy version of the tunnel that has been introduced to CrossBrowserTesting. If you use the new tunnel version, see Local Testing — Secure Tunnels.

I am writing a Visual Studio application and the application works on my machine but will not work on the local connection.

See here for a Stack Overflow explanation of the problem: https://stackoverflow.com/questions/14725455/connecting-to-visual-studio-…

There are a couple of ways to get around this. By default IIS Express will only serve content to URL that looks like this http://localhost.

Use smart proxy

If you decide to use this option, when you run the local connection you will need to pick the Proxy Server option in the local connection. You will put your IP address and the port of the smart proxy you will use. For Charles and Fiddler the port is usually 8888, you can check this in the proxy setting for either product.

Connection to a remote proxy server

Click the image to enlarge it.

Charles Proxy

Use the Enable Rewrite functionality to rewrite any Host header that comes in to your IP address and change it to the localhost format that IIS Express recognizes.

  1. Find the Rewrite menu option in the Tools menu.

    Tools menu
  2. Click Enable Rewrite and Debug in Error Log and create a new set, Add a location and leave it blank to get the "*" everything location, then finally add a Rule.

    Rewrite settings

    Click the image to enlarge it.

  3. In the rule make sure to include your IP address and port that the Visual Studio application is using.

    Rewrite rule settings

    Click the image to enlarge it.

  4. For HTTPS to work you have to make sure that Charles is set to Enable SSL Proxying, otherwise it will not be able to modify the SSL traffic. You can find that option under Proxy > SSL Proxying Settings. Make sure that Enable SSL Proxying is checked and your IP address is added as a location.

Fiddler proxy

Use the Custom Rules to change the Host header from your IP address to the localhost format IIS Express recognizes.

  1. In the Rules menu choose the Customize Rules menu option.

    Rules menu
  2. Find the method named OnBeforeRequest in the notepad that pops up.

    OnBeforeRequest method

    Click the image to enlarge it.

  3. At the bottom of the OnBeforeRequest method add the following code. Change the code to include your IP address and port that IIS Express is using for your application.

    if (oSession.HostnameIs("CHANGE TO YOUR IP ADDRESS")) {
        oSession.host ="localhost:YOUR_PORT_HERE";
    }

    Edited method

    Click the image to enlarge it.

Change the IIS Express setup

Changing the IIS Express setup on your machine so it allows connections other than localhost. You can either look at what theStack Overflow article https://stackoverflow.com/questions/14725455/connecting-to-visual-studio-… or our directions below.

  1. You will need to run Visual Studio as admin, if you do not do this these changes will not work.

  2. Backup this file: %userprofile%\documents\iisexress\applicationhost.xml.

  3. Edit this file: %userprofile%\documents\iisexress\applicationhost.xml.

  4. Find the site tag that matches your application.

  5. Find the bindings tag for your application.

  6. Change the binding (the PORT should match the port your application is using)

    <binding protocol="http" bindingInformation="*:58934:localhost" />

    to this

    <binding protocol="http" bindingInformation="*:58949:*" />

See Also

Testing on a Local Machine
CrossBrowserTesting Local Connection Tool
FAQ

Highlight search results