Last post Dec 08, 2005 06:19 AM by zootius
Nov 17, 2005 05:14 AM|Koen|LINK
I created a Url Rewriting solution based on some info I found on several post.
However, when I do a postback on one of the pages (click a submit button for instance) the underlying url is used, and the rewriting fails.
Any idea how I can solve this ?
this is in my Application_BeginRequest
strCurrentPath = Request.Path;
strCurrentPath = strCurrentPath.ToLower();
strCustomPath = UrlRewriter.GetURL(strCurrentPath);
the urlrewriter simply checks the syntax of the url and changes it into the correct on, based on information coming from the database.
public static string GetURL(string currentpath)
string strCurrentPath = currentpath.ToLower();
if (strCurrentPath.IndexOf("/articles/") > -1)
strCustomPath = "~/Articles.aspx?ID=" + System.IO.Path.GetFileNameWithoutExtension(strCurrentPath);
// rewrite the URL
thanks in advance
Nov 17, 2005 05:25 PM|ScottCate|LINK
Dec 02, 2005 08:56 PM|dontmindme|LINK
Dec 06, 2005 09:18 PM|hartwg|LINK
Scott's solution is not complete because it does not render all of the form tag's possible attributes, especially the OnSubmit attribute, which is set via Page.ClientScript.RegisterOnSubmitStatement (in 2.0). I would suspect that this is causing your problem.
It is not easy to render in the overridden HtmlForm class because it is accessalble only via internal methods on Page. There are at least two options for a complete solution:
1. Create a overridden HtmlTextWriter that strips out (or better yet replaces) the action attribute. This writer can be inserter into the process in the RenderChildren method of a overridden Page class. Since there are at least 2 different HtmlTextWriter
implementations, based on the browser's capabilities, the easiest solution I found was to create a proxied writer (via RealProxy). The performance hit is miniminal since it is only used to write out the Form control's rendering.
2. Create a response stream wrapper (set via the Context.Response.Filter property) that parses the output text and replaces the action attribute. Depending on how you do the parsing, this can be fairly expensive. One advantage of this appropach is that
it can be set inside the URL mapping module, making it transparent to the rest of the app.
My mapping solution actually uses both of these techniques, the first for most pages, the second as a fallback for any pages that aren't based on the correct class. Some fairly simple switching logic ensures that the highest performance path normally operates.
It works well an anything that I have tried to render- which includes a pretty large range of standard and custom controls, including some AJAX stuff.
Dec 07, 2005 02:36 PM|AndrewSeven|LINK
You could try using an IHttpHandlerFactory
Dec 08, 2005 06:19 AM|zootius|LINK
Have a look here:
Seems to be the second RewritePath that you're missing?