Apache Location-like behavior in ASP.NET (part II)
As I mentioned in my update to my last post, the custom URLs break down on postback because the form doesn't realize where it's supposed to post back to. To get around this, we need two new classes, a new Page base class and a custom HtmlTextWriter:
public class RewriteBaseClass: System.Web.UI.Page
{
protected override void Render(HtmlTextWriter writer)
{
CustomActionHtmlTextWriter customWriter = new CustomActionHtmlTextWriter(writer);
base.Render(customWriter);
}
}
and
public class CustomActionHtmlTextWriter : HtmlTextWriter
{
public CustomActionHtmlTextWriter(HtmlTextWriter baseWriter) : base(baseWriter)
{
}
public override void WriteAttribute(string name, string value, bool fEncode)
{
if( name == "action")
{
value = HttpContext.Current.Request.RawUrl;
}
base.WriteAttribute (name, value, fEncode);
}
}
This seems to work, although I'm not yet convinced it's the best way or without side-effects. Need to play with it a bit more.