Friday, May 27, 2011

Getting QueryString parameters from ReWritten URL in ASP.Net

After a URL is rewritten to merge querystring into the actual URL, to get the querystring params, you should look towards Request's RawUrl property.

Use this code to extract QueryString params from the raw url:
Uri theRealURL = new Uri(HttpContext.Current.Request.Url.Scheme + "://" + HttpContext.Current.Request.Url.Authority + HttpContext.Current.Request.RawUrl);  
string utm_source = HttpUtility.ParseQueryString(theRealURL.Query).Get("utm_source");  
Actual code from this blog

Sunday, May 15, 2011

ASP.Net - Redirecting with URL Rewriter

To redirect one URL to another, use this rule inside "rewriter" section: