简体   繁体   中英

login.aspx page should redirect to a different page

I am using Forms Authentication and have stored the credentials in the Web.config since there are only two credentials. Currently I have a login page that on authentication would redirect to the default.aspx page or the return url. I want to redirect to a different page ie form1.aspx or form2.aspx based upon the credentials. Currently using

if (FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text))
{
    FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false);
}

Something like this?

    if (FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text))
    {
            switch (txtUser.Text)
            {
                    case "alice":
                            Response.Redirect("form1.aspx");
                            break;
                    case "bob":
                            Response.Redirect("form2.aspx");
                            break;
                    default:
                            FormsAuthentication.RedirectFromLoginPage(txtUser.Text, false);
                            break;
            }
    }

Use Response.Redirect.

if (FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text)){
Response.Redirect("URLofPageYouWantToRedirectTo");
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM