Home Articles Packages Things


ASP.NET Url Rewriting and Postbacks

When you use url rewriting in combination with ASP.NET, postbacks tend not to go to the rewritten url but to the real url, which is then shown in the browser. .NET 3.5 SP1 includes new functionality on the Form-object which makes it easy to change that behaviour.

Given a normal serverside form:

<form runat="server" id="form1"></form>

all you have to do is add a single line of code to the Page_Load event handler:

form1.Action = Request.RawUrl;

Request.RawUrl contains the rewritten url. Setting the Action property on the form to that value makes the form post back to the rewritten url.