Programming Journal C#, Java, SQL and to a lesser extent HTML, CSS, XML, and regex. I made this so other programmers could benefit from my experience.

Friday, October 5, 2007

Help user redirect to secure target page after login and avoid extra navigation

Here's a solution for when the user needs to log in before accessing a secure page. This allows the user to avoid going through the menu system to go to the original page desired. I avoid some kind of error by using the false parameter in the redirect. The querystring of note is ReturnUrl.


protected void Page_Load(object sender, EventArgs e)
{
if (User.Identity.IsAuthenticated == false)
{
Response.Redirect("Login.aspx?ReturnUrl=DesiredPage.aspx", false);
}
else
{
MembershipUser user = Membership.GetUser().ProviderUserKey.ToString();
}
}

RedirectFromLoginPage Method

No comments: