Search This Blog

Sunday, March 7, 2010

How to elegantly handle ReturnUrl when using UrlRewrite in ASP.NET 2.0 WebForms - Stack Overflow

link -> How to elegantly handle ReturnUrl when using UrlRewrite in ASP.NET 2.0 WebForms - Stack Overflow
protected void Application_EndRequest(object sender, EventArgs e)
{
   
string redirectUrl = this.Response.RedirectLocation;
   
if (!this.Request.RawUrl.Contains("ReturnUrl=") && !string.IsNullOrEmpty(redirectUrl))
   
{
       
this.Response.RedirectLocation = Regex.Replace(redirectUrl, "ReturnUrl=(?'url'[^&]*)", delegate(Match m)
       
{
           
return string.Format("ReturnUrl={0}", HttpUtility.UrlEncode(this.Request.RawUrl));
       
}, RegexOptions.Singleline | RegexOptions.IgnoreCase | RegexOptions.ExplicitCapture);
   
}
}
I tested the checked solution at the bottom. It gets rid of the lookingglass stuff out of our URL when you get redirected to the login page. Still can't figure out how to get a hash tag on the server. ASP seems to strip them out of the URL even without forms authentication or URL rewriting.

No comments:

Post a Comment