471,350 Members | 1,729 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,350 software developers and data experts.

Plese help with my codes

Hi,

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.

TIA
Jun 27 '08 #1
1 893
"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.

Jun 27 '08 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

29 posts views Thread by Maurice LING | last post: by
3 posts views Thread by aman | last post: by
3 posts views Thread by c# beginner | last post: by
reply views Thread by XIAOLAOHU | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.