Forcing browser to reload the "same page" with "mapped URL"

Discussion in 'ASP .Net' started by Willy, Mar 28, 2008.

  1. Willy

    Willy Guest

    I have a website that uses querystrings on a certain page to show multiple
    contents.
    I have created mapped pages to hide the gory details of these querystrings.

    So instead of details.aspx?ID=kldjlkdjldsjlkds&cat=jjfjfj
    the client sees products.aspx

    I also use these "mapped" pages in my sitemap file.

    This site is multilingual so I have buttons on the page to switch languages.
    The switch works except that the thing insists on going to
    details.aspx?ID=kldjlkdjldsjlkds&cat=jjfjfj instead of products.aspx. This
    spoils the breadcrumbs that are linked to the sitemap file.

    The code I use is as simple as :
    Me.Page.Response.Redirect(Me.Page.Request.RawUrl.ToString, True)
    (rawurl contains products.aspx)
    Can somebody tell me what I am doing wrong ?

    Thanks a lot.
     
    Willy, Mar 28, 2008
    #1
    1. Advertising

  2. Can you post a "Short but complete" code sample that illustrates your issue?

    -- Peter
    Site: http://www.eggheadcafe.com
    UnBlog: http://petesbloggerama.blogspot.com
    Short Urls & more: http://ittyurl.net


    "Willy" wrote:

    > I have a website that uses querystrings on a certain page to show multiple
    > contents.
    > I have created mapped pages to hide the gory details of these querystrings.
    >
    > So instead of details.aspx?ID=kldjlkdjldsjlkds&cat=jjfjfj
    > the client sees products.aspx
    >
    > I also use these "mapped" pages in my sitemap file.
    >
    > This site is multilingual so I have buttons on the page to switch languages.
    > The switch works except that the thing insists on going to
    > details.aspx?ID=kldjlkdjldsjlkds&cat=jjfjfj instead of products.aspx. This
    > spoils the breadcrumbs that are linked to the sitemap file.
    >
    > The code I use is as simple as :
    > Me.Page.Response.Redirect(Me.Page.Request.RawUrl.ToString, True)
    > (rawurl contains products.aspx)
    > Can somebody tell me what I am doing wrong ?
    >
    > Thanks a lot.
    >
     
    Peter Bromberg [C# MVP], Mar 30, 2008
    #2
    1. Advertising

  3. Willy

    Willy Guest

    web.config:
    <?xml version="1.0"?>
    ....
    <system.web>
    <urlMappings enabled="true">
    <add url="~/jake.aspx" mappedUrl="~/default.aspx"/>
    </urlMappings>
    </system.web>
    </configuration>

    default.aspx:
    Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button1.Click
    Server.Transfer(Me.Request.RawUrl)
    End Sub

    Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button2.Click
    Response.Redirect(Me.Request.RawUrl, False)
    End Sub

    Protected Sub Button2_Load(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Button2.Load
    Button2.Text = "redirect " & Me.Request.RawUrl
    End Sub
    End Class

    Now I visit the page jake.aspx (which doesn't exist : it is a mapped file).
    My browser shows Jake.aspx
    I click any of the buttons to "refresh" the current page (I change the
    language of the current thread in the meantime).
    My browser shows Default.aspx. But I want it to be jake.aspx

    "Peter Bromberg [C# MVP]" <> wrote in message
    news:...
    > Can you post a "Short but complete" code sample that illustrates your
    > issue?
    >
    > -- Peter
    > Site: http://www.eggheadcafe.com
    > UnBlog: http://petesbloggerama.blogspot.com
    > Short Urls & more: http://ittyurl.net
    >
    >
    > "Willy" wrote:
    >
    >> I have a website that uses querystrings on a certain page to show
    >> multiple
    >> contents.
    >> I have created mapped pages to hide the gory details of these
    >> querystrings.
    >>
    >> So instead of details.aspx?ID=kldjlkdjldsjlkds&cat=jjfjfj
    >> the client sees products.aspx
    >>
    >> I also use these "mapped" pages in my sitemap file.
    >>
    >> This site is multilingual so I have buttons on the page to switch
    >> languages.
    >> The switch works except that the thing insists on going to
    >> details.aspx?ID=kldjlkdjldsjlkds&cat=jjfjfj instead of products.aspx.
    >> This
    >> spoils the breadcrumbs that are linked to the sitemap file.
    >>
    >> The code I use is as simple as :
    >> Me.Page.Response.Redirect(Me.Page.Request.RawUrl.ToString,
    >> True)
    >> (rawurl contains products.aspx)
    >> Can somebody tell me what I am doing wrong ?
    >>
    >> Thanks a lot.
    >>
     
    Willy, Mar 30, 2008
    #3
  4. Willy

    Willy Guest

    So ? I posted a sample, didn't I?

    > web.config:
    > <?xml version="1.0"?>
    > ...
    > <system.web>
    > <urlMappings enabled="true">
    > <add url="~/jake.aspx" mappedUrl="~/default.aspx"/>
    > </urlMappings>
    > </system.web>
    > </configuration>
    >
    > default.aspx:
    > Partial Class _Default
    > Inherits System.Web.UI.Page
    >
    > Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button1.Click
    > Server.Transfer(Me.Request.RawUrl)
    > End Sub
    >
    > Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button2.Click
    > Response.Redirect(Me.Request.RawUrl, False)
    > End Sub
    >
    > Protected Sub Button2_Load(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Button2.Load
    > Button2.Text = "redirect " & Me.Request.RawUrl
    > End Sub
    > End Class
    >
    > Now I visit the page jake.aspx (which doesn't exist : it is a mapped
    > file).
    > My browser shows Jake.aspx
    > I click any of the buttons to "refresh" the current page (I change the
    > language of the current thread in the meantime).
    > My browser shows Default.aspx. But I want it to be jake.aspx
    >
     
    Willy, Apr 1, 2008
    #4
  5. It's a common problem with URL rewriting.
    I am not sure how <urlMappings> works. I always did my own custom URL
    rewrite... So you will have to dig a little to find a remedy.

    but here is the problem...

    <form> tag in asp.net pages have an action set. And it's set to current
    page.
    So when url rewriting happens browser hits "/jake.aspx", url rewriting
    rewrites it to "/default.aspx" and makes ASP.NET think that it hit
    "/default.aspx"

    But action property of the <form> has "/deault.aspx" cause ASP.NET thinks
    that browser hit "/default.aspx", So as sson as you press the any button on
    the form browser hits "/default.aspx" with a postback..

    So here is the possible solutions...

    1. make your own MyHtmlForm class that derived from HtmlForm and suppress
    action property when outputting to browser
    check out this article
    http://www.codeproject.com/KB/aspnet/SmartFormControl.aspx

    2. If somehow you can find out original URL rewrite it back (wiht
    HttpContext.RewritePath) before page is rendered to make HtmlForm output
    "/jake.aspx" in action property.



    George.



    "Willy" <> wrote in message
    news:...
    > So ? I posted a sample, didn't I?
    >
    >> web.config:
    >> <?xml version="1.0"?>
    >> ...
    >> <system.web>
    >> <urlMappings enabled="true">
    >> <add url="~/jake.aspx" mappedUrl="~/default.aspx"/>
    >> </urlMappings>
    >> </system.web>
    >> </configuration>
    >>
    >> default.aspx:
    >> Partial Class _Default
    >> Inherits System.Web.UI.Page
    >>
    >> Protected Sub Button1_Click(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Button1.Click
    >> Server.Transfer(Me.Request.RawUrl)
    >> End Sub
    >>
    >> Protected Sub Button2_Click(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Button2.Click
    >> Response.Redirect(Me.Request.RawUrl, False)
    >> End Sub
    >>
    >> Protected Sub Button2_Load(ByVal sender As Object, ByVal e As
    >> System.EventArgs) Handles Button2.Load
    >> Button2.Text = "redirect " & Me.Request.RawUrl
    >> End Sub
    >> End Class
    >>
    >> Now I visit the page jake.aspx (which doesn't exist : it is a mapped
    >> file).
    >> My browser shows Jake.aspx
    >> I click any of the buttons to "refresh" the current page (I change the
    >> language of the current thread in the meantime).
    >> My browser shows Default.aspx. But I want it to be jake.aspx
    >>

    >
     
    George Ter-Saakov, Apr 2, 2008
    #5
  6. Willy

    Willy Guest

    Hello George,

    All I needed to do was add code
    Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
    System.EventArgs) Handles Me.PreRender
    Me.Context.RewritePath(Me.Request.RawUrl)
    End Sub
    to my page to make it work. I didn't know about the *rewritePath* trick.
    But it will sure go into my basket
    I checked with SiteMapPath control and this one is also very happy.

    Thanks a lot.
    Van den Driessche Willy.
     
    Willy, Apr 3, 2008
    #6
  7. Cool, that was easier than I thought.
    I thought that RawUrl will point to already rewritten Url.

    George.

    "Willy" <> wrote in message
    news:...
    > Hello George,
    >
    > All I needed to do was add code
    > Protected Sub Page_PreRender(ByVal sender As Object, ByVal e As
    > System.EventArgs) Handles Me.PreRender
    > Me.Context.RewritePath(Me.Request.RawUrl)
    > End Sub
    > to my page to make it work. I didn't know about the *rewritePath* trick.
    > But it will sure go into my basket
    > I checked with SiteMapPath control and this one is also very happy.
    >
    > Thanks a lot.
    > Van den Driessche Willy.
     
    George Ter-Saakov, Apr 4, 2008
    #7
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. WAZOO

    forcing a page reload?

    WAZOO, Apr 29, 2004, in forum: ASP .Net
    Replies:
    4
    Views:
    592
    Øystein Fallo
    Apr 30, 2004
  2. Rob Meade

    Forcing a reload?

    Rob Meade, Jul 6, 2006, in forum: ASP General
    Replies:
    1
    Views:
    131
    Rob Meade
    Jul 6, 2006
  3. Stefan Mueller
    Replies:
    4
    Views:
    298
    Stefan Mueller
    Nov 5, 2005
  4. Sonnich

    forcing parent window to reload

    Sonnich, Nov 16, 2006, in forum: Javascript
    Replies:
    2
    Views:
    118
    Sonnich
    Nov 16, 2006
  5. Edward Diener
    Replies:
    11
    Views:
    440
    Bart Van der Donck
    Oct 26, 2007
Loading...

Share This Page