Internet Handholding posted on January 25, 2012 04:59
When you use Visual Studio to develop a website application and you run the website in the Visual Studio debugger you get a url like this.
http://localhost:50043/appl/default.aspx
Notice the /appl in the above url. When you deploy the website, your url looks like this.
http://www.domain.ext/default.aspx
Notice there is no /appl. This causes a big problem, because when you reference a url in your website starting with the root (/), you get different results when you are in the debugger than when in production.
For example, in your website you may want to reference your home page with some code like this.
<a href="/">Home</a>
This does not work in both environments. This problem happens with images, css, javascripts and so on.
I found a solution on this page that I believe is the best.
http://devtoolshed.com/content/fixing-relative-paths-c-aspnet-when-using-url-rewriting
The solution is to change your development project properties Virtual Path setting to / and remove the application name. Then your development and production environments will work the same. How simple.
In Visual Studio, in Solution Explorer, right click your project and select Properties Window. Change the Vritual Path to /.
Now you can just use / to refer to the root of your website. Simplifies everything you are doing.
That page had some coding solutions. Some clever coding solutions were also on this page.
http://stackoverflow.com/questions/89418/reference-app-relative-virtual-paths-in-css-file
After spending two weeks writing code to handle this problem, and the code works well, I much prefer setting the Virtual Path property to /.
Simplifying code and coding consistency are good things.