Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Forcing browser to reload the "same page" with "mapped URL"

Reply
Thread Tools

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

 
 
Willy
Guest
Posts: n/a
 
      03-28-2008
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.T oString, True)
(rawurl contains products.aspx)
Can somebody tell me what I am doing wrong ?

Thanks a lot.

 
Reply With Quote
 
 
 
 
Peter Bromberg [C# MVP]
Guest
Posts: n/a
 
      03-30-2008
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.T oString, True)
> (rawurl contains products.aspx)
> Can somebody tell me what I am doing wrong ?
>
> Thanks a lot.
>

 
Reply With Quote
 
 
 
 
Willy
Guest
Posts: n/a
 
      03-30-2008
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]" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.T oString,
>> True)
>> (rawurl contains products.aspx)
>> Can somebody tell me what I am doing wrong ?
>>
>> Thanks a lot.
>>


 
Reply With Quote
 
Willy
Guest
Posts: n/a
 
      04-01-2008
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
>


 
Reply With Quote
 
George Ter-Saakov
Guest
Posts: n/a
 
      04-02-2008
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...rmControl.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" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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
>>

>



 
Reply With Quote
 
Willy
Guest
Posts: n/a
 
      04-03-2008
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.

 
Reply With Quote
 
George Ter-Saakov
Guest
Posts: n/a
 
      04-04-2008
Cool, that was easier than I thought.
I thought that RawUrl will point to already rewritten Url.

George.

"Willy" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> 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.



 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Forcing a browser to re-render an image from its URL location andnot from the browser's cache Edward Diener Javascript 11 10-26-2007 08:18 PM
forcing parent window to reload Sonnich Javascript 2 11-16-2006 05:05 PM
Forcing a reload? Rob Meade ASP General 1 07-06-2006 07:02 PM
How to get and cancel the reload event (F5, Reload nutton, ...) within a browser Stefan Mueller Javascript 4 11-05-2005 06:09 PM
forcing a page reload? WAZOO ASP .Net 4 04-30-2004 07:19 AM



Advertisments