473,382 Members | 1,752 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

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

URL Rewriting - problems with postbacks

Hi All,

I am experimenting with URL Rewriting using the techniques outlined by Scott
Mitchell in his article "URL Rewriting in ASP.NET"
(http://msdn.microsoft.com/library/de...-us/dnaspp/htm
l/urlrewriting.asp).

In the article he mentions a problem with postbacks: "If the URLs you are
rewriting contain a server-side Web Form and perform postbacks, when the
form posts back, the underlying URL will be used". His solution is to use a
custom ActionlessForm derived from System.Web.UI.HtmlControls.HtmlForm, but
with the "action" attribute removed.

An alternative solution is outlined by Scott Allen in his blog entry "The
Passion and the Fury of URL Rewriting"
(http://odetocode.com/Blogs/scott/arc...9/22/509.aspx). He proposes
simply adding the following to Page_Load:
Context.RewritePath(Request.RawUrl);

However in my experimenting, it seems that neither of these solutions works
in one particular situation, and I'm wondering if anyone out there can help
out.

The situation is:
Redirect from: ~/products/
Redirect to: ~/Somedirectory/Somepage.aspx
Note that the "Redirect from" url does *not* contain a page name.

I have got this working fine for the first time the page is hit, having
created a /products sub-folder containing an empty Default.aspx page.

The problem is, when Somepage.aspx posts back to itself, using Scott Allen's
technique described above, the URL is rewritten *not* to ~/products/ (which
is what I want), but to ~/products/Default.aspx. While this is better than
the URL being rewritten to ~/Somedirectory/Somepage.aspx on postback, it
still isn't perfect!

And using Scott Mitchell's ActionlessForm, I get: "HTTP 405 - Resource not
allowed, The page you are looking for cannot be displayed because the page
address is incorrect". This is quite a long way from perfect.

Can anyone help?

TIA,

JON

Jul 21 '05 #1
6 8584
Hi Jon:

Here is what I think is happening.

When the browser requests the ~/products/ directory, IIS sees the
request is for a directory, checks the settings for the directory and
moves the request to the default document (default.aspx) since the
file exists on the file system. ASP.NET actually does see the URL as
~/products/default.aspx, because IIS has moved the request to this
location all by itself.

There are ways to get the original request (for the products
directory), which would be to make all requests go through the asp.net
runtime (enter a * in the script mapping). Then you really could
redirect from ~/products/ to /somedirectory/somepage.aspx, the problem
is I'm not sure how to get the action tag set correctly. You might
need to do something along the lines of:
http://weblogs.asp.net/jezell/archiv.../15/90045.aspx
to pull this off.

I hope to get some time to experiment with this interesting problem
this weekend.

--
Scott
http://www.OdeToCode.com/

On Fri, 8 Oct 2004 17:46:27 +0100, "Jon Maz" <jo****@surfeuNOSPAM.de>
wrote:
Hi All,

I am experimenting with URL Rewriting using the techniques outlined by Scott
Mitchell in his article "URL Rewriting in ASP.NET"
(http://msdn.microsoft.com/library/de...-us/dnaspp/htm
l/urlrewriting.asp).

In the article he mentions a problem with postbacks: "If the URLs you are
rewriting contain a server-side Web Form and perform postbacks, when the
form posts back, the underlying URL will be used". His solution is to use a
custom ActionlessForm derived from System.Web.UI.HtmlControls.HtmlForm, but
with the "action" attribute removed.

An alternative solution is outlined by Scott Allen in his blog entry "The
Passion and the Fury of URL Rewriting"
(http://odetocode.com/Blogs/scott/arc...9/22/509.aspx). He proposes
simply adding the following to Page_Load:
Context.RewritePath(Request.RawUrl);

However in my experimenting, it seems that neither of these solutions works
in one particular situation, and I'm wondering if anyone out there can help
out.

The situation is:
Redirect from: ~/products/
Redirect to: ~/Somedirectory/Somepage.aspx
Note that the "Redirect from" url does *not* contain a page name.

I have got this working fine for the first time the page is hit, having
created a /products sub-folder containing an empty Default.aspx page.

The problem is, when Somepage.aspx posts back to itself, using Scott Allen's
technique described above, the URL is rewritten *not* to ~/products/ (which
is what I want), but to ~/products/Default.aspx. While this is better than
the URL being rewritten to ~/Somedirectory/Somepage.aspx on postback, it
still isn't perfect!

And using Scott Mitchell's ActionlessForm, I get: "HTTP 405 - Resource not
allowed, The page you are looking for cannot be displayed because the page
address is incorrect". This is quite a long way from perfect.

Can anyone help?

TIA,

JON


Jul 21 '05 #2
Hi Scott,

Glad to know you're on the case! Looking forward to seeing what you come up
with...

Cheers,

JON
Jul 21 '05 #3
Well, I fiddled around with the second RewritePath and I did not come
up with a way around the problem. I think the solution will involve
overriding the HtmlForm class methods. I'll keep plugging away at this
when I get a chance but I'm afraid it's not going to be an elegant
solution I was hoping to find!
--
Scott
http://www.OdeToCode.com/

On Mon, 11 Oct 2004 10:14:57 +0100, "Jon Maz" <jo****@surfeuNOSPAM.de>
wrote:
Hi Scott,

Glad to know you're on the case! Looking forward to seeing what you come up
with...

Cheers,

JON


Jul 21 '05 #4
Hi Scott,

An inelegant solution is a lot better than no solution at all! Good to know
I'm not alone with this problem...

Thanks for the help,

JON
Jul 21 '05 #5
pm
http://www.alistapart.com/articles/footers/

"Jon Maz" wrote:
Hi Scott,

Glad to know you're on the case! Looking forward to seeing what you come up
with...

Cheers,

JON

Jul 21 '05 #6
Did you mean this article: http://www.alistapart.com/articles/urls/ ?

If so, the article discusses Apache's mod_rewrite, and has only this to say
about IIS: "Unfortunately IIS does not come with a rewrite mechanism. You
can write an ISAPI filter to do this for you."

J
---
Outgoing mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.775 / Virus Database: 522 - Release Date: 08/10/2004
Jul 21 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Brad | last post by:
In a portal like application I'm using rewritepath to change from fake friendly urls back to a central "default" page that actually serves all of the urls. It works quite well, except... if the...
2
by: Jon Maz | last post by:
Hi All, I've been looking into options for URL Rewriting in .net, and to be honest, I haven't seen anything that's easier than the old Classic Asp solution with an ISAPI filter redirecting to an...
2
by: R-D-C | last post by:
Can these two functions coexist? We have a web site where the querystrings are removed using URL Rewriting. Instead the page appears to be a html page with a long name (containing what would be...
0
by: Anonieko | last post by:
Jefrey Palermo How to do Url Rewriting with just an HttpHandler (without the side-effects) - level 400 posted on Wednesday, August 10, 2005 7:21 PM If you are interested in doing Url Rewriting...
6
by: Jon Maz | last post by:
Hi All, I am experimenting with URL Rewriting using the techniques outlined by Scott Mitchell in his article "URL Rewriting in ASP.NET"...
2
by: tacmec | last post by:
ASP.NET 2.0 (C#) application. I have a web form with a GridView, which is populated dynamically. See the code below. First time to the page, IsPostBack is false. Therefore, DisplayItems() is...
3
by: MatsL | last post by:
Hi, I'm using Context.RewritePath() in a HttpModule to get url rewriting done. http://localhost/Web1/articles -> http://localhost/Web1/Default.aspx?m=articles But I'm having problems with...
3
by: Smokey Grindel | last post by:
I am using ASP.NET 2.0 and know about the static list in the web.config for URL rewriting, but my list is dynamic and I am running into some problems... 1) How do you get URL rewriting to work in...
409
by: jacob navia | last post by:
I am trying to compile as much code in 64 bit mode as possible to test the 64 bit version of lcc-win. The problem appears now that size_t is now 64 bits. Fine. It has to be since there are...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?

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.