Wednesday, May 2, 2007

ASP.Net Membership ReturnUrl Problem

If you click the Login link on the main page, ASP.Net will auto create a ReturnUrl Querystring. After you logged in succesfully you will be redirected to the page you came from. The problem is that the DestinationPageUrl property won't work anymore if you have a ReturnUrl Querystring. This causes a problem for us because the user will be redirected to the login page instead of the DestinationPageUrl.

We've searched for solutions but there isn't a clean solution. Here's a way to solve the problem (redirect to the Default page if a ReturnUrl querystring is present).

protected void Page_Load(object sender, EventArgs e)
{
string strRedirect;
strRedirect = Request["ReturnUrl"];
if (strRedirect != null)
Response.Redirect("~/Default.aspx", true);
}

1 comment:

Anonymous said...

nice job Jonas!