"Raymon Du" <rd**@yahoo.comwrote in message
news:uo**************@TK2MSFTNGP06.phx.gbl...
This is te first time I use url rewriting. What I am trying to accomplish:
Hide the .aspx extension and give user a shorter path to type, say the
user can type "/sales" in browser and the browser will display
"/topic.aspx?topic=sales"
To do this, I created a "sales" folder and put a dummy "default.aspx" in
it, then I tried the following codes:
protected void Application_BeginRequest(Object sender, EventArgs e)
{
if (Request.Path.ToLowerInvariant().IndexOf("sales/default.aspx")
!= -1)
HttpContext.Current.RewritePath("/topic.aspx?topic=sales");
if (Request.Path.ToLowerInvariant().IndexOf("support/default.aspx")
!= -1)
HttpContext.Current.RewritePath("/topic.aspx?topic=support");
the browser displays the correct html, but all the images become broken
and all links are linked to "sales" folder instead of application root. I
know I did it wrong, just don't know how to correct it.
When your HTML page contains an <img src='whatever'>, it is the browser
the one that "builds" the URL of the image and requests it from the server.
If you are using is a relative path, the browser will append it to whatever
it thinks is the current page and then request that from the server. If you
are using URL rewriting, the path that the browser "sees" is different from
the real path of the page, so it is sending to the server a request that
doesn't match the path that you intended for that image.
The easiest remedy is to use absolute urls for your images instead of
relative urls, or to move the images into a path that matches your rewritten
urls. A more sophisticated approach would use a different extension for the
images (for instance, .ashx instead of .jpg) so that they are routed into
aspnet rather than being served directly by IIS, and then performing url
rewriting also for the images and not only for the pages.