IIS Url Rewriting - avoid repeat of querystring parameters

Using the URL rewriting mechanism of IIS causes repeat of querystring parameters on every postback, because it builds the postaback url (rewrites url) by appending the querystring to current url.

Actual url:
/product.aspx?type=hats

Rewritten url:
/product/hats

Rewritten url after postback:
/product/hats?type=hats
which is actually equal to /product.aspx?type=hats&type=hats
So the type value is "hats,hats".

To avoid repeat of querystring variables simply check if the url is already rewritten:

protected void Page_Load(object sender, EventArgs e)
{
if ( !String.IsNullOrEmpty(Request.ServerVariables["HTTP_X_ORIGINAL_URL"]) )
{
form1.Action = Request.ServerVariables["HTTP_X_ORIGINAL_URL"];
}
}

Detailed description:

No comments:

Post a Comment