Anas Ghanem

<ItemTemplate ".Net Tips" runat="Weblogs.asp.net" Country="WestBank" />

Redirecting the Users to different pages based on there roles

while working with login control , you can redirect the users to a different pages base on there roles , to do this , you need to handle theLoggedIn event for  login control   which is fired after the user logged in successfully ,

 

Assume we have 2 roles , Admins and Editors ..

and assume that every role has its own directory ,

you can check the user role and  redirect the user in the loggedIn event handler of the Login control as follows:

 

protected void Login1_LoggedIn(object sender, EventArgs e) {

if(Roles.IsUserInRole("Admins"))

  Response.Redirect("~/Admins/Default.aspx");

   else if(Roles.IsUserInRole("Editors"))

    Response.Redirect("~/Editors/Default.aspx");

}

 

Regards,

Anas Ghanem

Posted: Apr 12 2008, 09:19 PM by anas | with 5 comment(s) |
Filed under: ,

Comments

thiwanka said:

Hi, This is Very useful tip. thanks lot.

# May 3, 2008 8:46 AM

noisychatterboxer said:

it does not work for me , i was always redirected to the  

page that was not expected to be even though i assign the roles correctly to user

# May 13, 2008 8:57 AM

luciano said:

the same for me...it does not work....any suggestion?

# May 26, 2008 11:41 AM

anas said:

Why  ? are you using windows authentication Or forms authentication ?

note sure why ..

did you wrote that code in the login control  LoggedIn event ?

you can ask the question and show the details

on security forums: http://forums.asp.net/25.aspx

# May 26, 2008 1:50 PM

yasserzaid said:

Hi

just change

Response.Redirect("~/Admins/Default.aspx");

with

Login1.DestinationPageUrl = "~/Admin/Default.aspx";

Good Luck

# June 25, 2008 5:25 AM
Leave a Comment

(required) 

(required) 

(optional)

(required)