Archive

Archive for July 7th, 2006

FormRewrite.dll

July 7th, 2006

For those of you who love dabbling with rewriting URLs, you have most probably become aware that Dot Net 2.0+ handles postbacks and viewstates differently to Dot Net 1.x. The action attribute within the form tag sends postbacks back to the physical page, and not the rewritten page, causing a viewstate validation error due to the tighter security of the second framework.

This is not a big problem however. To solve this, all we need to do is rewrite the location of the action attribute to the rewritten url. If you can do this, great, but an easier solution is to leave the action attribute blank, which has the effect of sending the form back to the same page - Excellent, that’s what we want, with hardly any effort. ;)

Firstly download FormRewrite.dll and place in your bin directory (Legacy - Currently unavailable)

Secondly we need to rewrite the form’s action attribute; place this code into every page that is rewritten and perform postbacks. If you use master pages, place it in there instead.

Add to the first line of your file

Imports Denaploy.Sys.Rewrite

And this within your class

  Protected Overrides Sub Render(ByVal writer As System.Web.UI.HtmlTextWriter)
    writer = New FormRewrite(writer, " ", HttpContext.Current.Items("VirtualPath"))
    MyBase.Render(writer)
  End Sub

Techie ,