Plese help with my codes

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Raymon Du

    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?topi c=sales"

    To do this, I created a "sales" folder and put a dummy "default.as px" in it,
    then I tried the following codes:

    protected void Application_Beg inRequest(Objec t sender, EventArgs e)
    {
    if (Request.Path.T oLowerInvariant ().IndexOf("sal es/default.aspx")
    != -1)
    HttpContext.Cur rent.RewritePat h("/topic.aspx?topi c=sales");
    if (Request.Path.T oLowerInvariant ().IndexOf("sup port/default.aspx")
    != -1)
    HttpContext.Cur rent.RewritePat h("/topic.aspx?topi c=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


  • Alberto Poblacion

    #2
    Re: Plese help with my codes

    "Raymon Du" <rdrd@yahoo.com wrote in message
    news:uowPf5HvIH A.6096@TK2MSFTN GP06.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?topi c=sales"
    >
    To do this, I created a "sales" folder and put a dummy "default.as px" in
    it, then I tried the following codes:
    >
    protected void Application_Beg inRequest(Objec t sender, EventArgs e)
    {
    if (Request.Path.T oLowerInvariant ().IndexOf("sal es/default.aspx")
    != -1)
    HttpContext.Cur rent.RewritePat h("/topic.aspx?topi c=sales");
    if (Request.Path.T oLowerInvariant ().IndexOf("sup port/default.aspx")
    != -1)
    HttpContext.Cur rent.RewritePat h("/topic.aspx?topi c=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.

    Comment

    Working...