Sunday, July 11, 2010

fix to login control's behavior on rewrited urls

protected void Application_EndRequest(object sender, EventArgs e)
{
if (Response.StatusCode == 302 && !string.IsNullOrEmpty(Response.RedirectLocation)) //if valid url and with redirect location
{
const string LOGINPAGE = "login.aspx";
string targetLocation = Response.RedirectLocation.ToLower();

//check if user is trying to login from a rewrited page
if ((Request.HttpMethod == Classes.Constants.HTTP_POST) && Request.RawUrl != Request.Url.PathAndQuery)
{
if (targetLocation.Contains(LOGINPAGE)
&& targetLocation.Contains(Classes.Constants.QS_RETURNURL.ToLower()))

//modify redirectlocation's return url with the rewrited url
Response.RedirectLocation = string.Format("{0}?{1}={2}",
VirtualPathUtility.ToAbsolute(Classes.Constants.PAGE_LOGIN),
Classes.Constants.QS_RETURNURL,
Server.UrlEncode(Request.RawUrl) //the rewrited url
);
}
}
}


Share/Save/Bookmark

No comments:

Post a Comment