You are here:   Home > Asp.net
  |  Login

Programmer Newsletter

Minimize

Master Programmer

Minimize

Find articles on computer software, programming, ASP.net, Sql server, databases, C#, websites, Internet, Windows, Outlook macros.

Programming Articles

Minimize
25

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.

Posted in: Asp.net

Post Rating

Comments

There are currently no comments, be the first to post one.

Post Comment

Only registered users may post comments.

Programmer Newsletter

Minimize

Subscribe to the Internet Handholding newsletter



Reccomend Programmer.bz

Minimize

Share/Bookmark Bookmark and Share