Recently I run into a strange situation that one of my pages was always loaded twice for each reqeust. This happened only when I enable “URL Rewrite” feature for the site. After almost a hour of debugging, I found it’s caused by a line in stylesheet like this:
In a regular, non-URLRewrite case, the broswer will correctly render the relative location of this image from the web page, which is at the root folder. It will resolve the location of mypic.gif to be /images/mypic.gif.
However, when URL rewrite was turned on, my page’s URL changed from /JobDetails.aspx?id=123 to /Jobs/Orange County/IT/123/Web Designer Needed. For the broswer, the page is located at many levels deep from the root. As the result, the path of above image will be resolved to /Jobs/Orange+County/IT/123/Web+Designer Needed/images/mypic.gif.
The retrieval of the image is a separate GET HTTP request from the broswer. Unfortunately, the URL of the image happens to match one of the URL rewrite rules. The result: this image request gets to translated to /JobDetails.aspx?id=123 and this ASPX page is requested twice!
Lesson: always use absolute path, espacially when URL rewrite is used.