I've seen a couple of posts to ASP.NET forums to the effect of “URLRewriting is dumb because the action attribute of the form tag will point to the wrong place.” What you need to do is to create your own version of the HtmlTextWriter class that overrides the default behavior. Here's what I came up with:
public
class MyWriter: HtmlTextWriter{ bool blnIsForm = false;
private TextWriter writer;
public MyWriter(TextWriter writer): base(writer)
{
this.writer = writer;
}
public MyWriter(TextWriter writer, string tabString): base(writer, tabString)
{
this.writer = writer;
}
public override void RenderBeginTag(string tagName)
{
blnIsForm = String.Compare(tagName,"form") == 0;
base.RenderBeginTag (tagName);
}
public override void WriteAttribute(string name, string value, bool fEncode)
{
if(String.Compare(name, "action", true) == 0)
{
value = "";
}
base.WriteAttribute (name, value, fEncode);
}
}
So there you have it Jimmy-Jimmy. The important parts of this are the RenderBeginTag checks to see if it is currently rendering a form tag and the WriteAttribute checks to see if it is rendering the action attribute and, if so, it just changes the actual value with an empty string. In a later post, I will show how to call this new writer from the Page object.
By the way ... does anyone have a better way to insert code into a post than pasting it in and then modifying the HTML?