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

W

Willy

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.
 
W

Willy

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
 
G

George Ter-Saakov

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.
 
W

Willy

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.
 
G

George Ter-Saakov

Cool, that was easier than I thought.
I thought that RawUrl will point to already rewritten Url.

George.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top