Lady Blue
Lady Blue

Reputation: 5

Redirect according to roles

I have two roles: administrator and users. In my login page, how do I redirect each of these two roles to a different page? For example, once an administrator has logged in they should be redirected to Page A while a user should be redirected to Page B. I have created the login control in login page and I used forms authentication.

Upvotes: 0

Views: 227

Answers (2)

Leo the Lion
Leo the Lion

Reputation: 1

First create the Column of UserRole with UserName and Password in Database.When the User logs In, If the user is valid, then return the UserRole Value of the user from Database. Check the role at the time of login process and redirect the user on the base of value.

Upvotes: 0

lukiffer
lukiffer

Reputation: 11293

Just check their role and do a normal Response.Redirect like so:

void btnLogin_Click(object sender, EventArgs e)
{
    if (HttpContext.Current.User.IsInRole("Administrators"))
        Response.Redirect("~/PageA.aspx");
    else
        Response.Redirect("~/PageB.aspx");
}

Upvotes: 2

Related Questions