J
Jon Maz
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/default.asp?url=/library/en-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/archive/2004/09/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
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/default.asp?url=/library/en-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/archive/2004/09/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