Override the html form in ASP.NET for URL rewriting

Feb 20, 2006

If you are using URL rewriting, the ASP.NET HTML form tag doesn't support it. You have to override the form tag in order to make it work. It was a bug in ASP.NET 1.x and still haven't been fixed in 2.0. Here is the class I use when doing URL rewriting.

using System;
using System.Web;
using System.Web.UI;

public class Form : System.Web.UI.HtmlControls.HtmlForm
{
 protected override void RenderAttributes(HtmlTextWriter writer)
 {
  writer.WriteAttribute("name", this.Name);
  base.Attributes.Remove("name");

  writer.WriteAttribute("method", this.Method);
  base.Attributes.Remove("method");

  this.Attributes.Render(writer);

  writer.WriteAttribute("action", HttpUtility.HtmlEncode(Context.Request.RawUrl));
  base.Attributes.Remove("action");

  writer.WriteAttribute("onsubmit", "if (typeof(WebForm_OnSubmit) == 'function') return WebForm_OnSubmit();");
  base.Attributes.Remove("onsubmit");

  if (base.ID != null)
  writer.WriteAttribute("id", base.ClientID);
 }
}

* Only $4.95/month ASP.NET & Windows 2008 + IIS 7 Hosting! FREE SQL Included

Comments (1) -

Penis Enlargement
Penis Enlargement Armenia
9/26/2008 7:15:21 AM #

penis enlargement medicines to enlarge penis size naturally with world's best penis enlargement techniques, solutions and methods that enlarge penis size, boost sexual life and gives you confidence. www.penisenlargementmedicines.com

Comments are closed

About the author

Mads Kristensen

Mads Kristensen
Program Manager at the Microsoft Web Platform team and founder of BlogEngine.NET.

More...

Month List

Disclaimer

The opinions expressed herein are my own personal opinions and do not represent my employer’s view in any way.