Using Visual Studio to run web-sites locally using real domains

Visual Studio is great for developing and testing web-sites, but by default it runs them under a localhost address using a randomly generated port number, as given in the property page for the web-site:

Visual Studio Real Domains 01

This is fine, but sometimes it’s useful to have sites run at a location that looks more like a real internet URL, especially if you plan on including functionality that manipulates the URL for redirects etc… I’ve also encountered issues creating cookies using the default http://localhost:xxxx address.

Fortunately, there’s a hosts file trick you can use to make Visual Studio run sites under more realistic URLs. First point at the URL you want to use in your hosts file, for example:

Note though that if the URL you are using points to a real web-site on the internet, you won’t be able to access that site again until you remove the entry from your host file.

Then edit the property pages so that you’re using the Visual Studio Development Server, a specific port (rather than an auto-assigned port) and a custom start URL containing your chosen port number and test URL, for example:

Your property pages should look like this:

Visual Studio Real Domains 02

Then, when you run your web-site using Visual Studio, it will use as the base URL. All paths relative to that should work as expected:

Visual Studio Real Domains 03

Solved: “Value does not fall within the expected range” error when opening app.config or web.config in Visual Studio 2012

I recently started getting the follow error in Visual Studio 2012 when I tried to open any configuration file:

Error: Value does not fall within the expected range

It took a bit of working out, but the solution for me was as follows:

  • Close Visual Studio
  • Browse to the top level folder where the solution is located in Windows Explorer
  • Search for and delete files matching the following two patterns: *.user, *.suo
  • Restart Visual Studio

That should do the trick.