Anas Ghanem

ASP.NET from the middle east

Syndication

Sponsors

News


    Subscribe in a reader
Redirecting the Users to different page based on there roles

Hi,

While working with login control , you may need to redirect each user for a different page based on there roles.To do this , you can handle the LoggedIn event of login control( which will be  fired after the user logged in successfully)


protected void Login1_LoggedIn(object sender, EventArgs e)
{
// please don't use User.IsInRole here , because it will not be populated yet at this stage.

if (Roles.IsUserInRole(Login1.UserName, "Admins"))
Response.Redirect(
"~/Admins/Default.aspx");
else if (Roles.IsUserInRole(Login1.UserName, "Editors"))
Response.Redirect(
"~/Editors/Default.aspx");
}


Regards,

Anas Ghanem

Published Saturday, April 12, 2008 11:19 PM by anas
Filed under: ,

Comments

# re: Redirecting the Users to different pages based on there roles@ Saturday, May 03, 2008 8:46 AM

Hi, This is Very useful tip. thanks lot.

# re: Redirecting the Users to different pages based on there roles@ Tuesday, May 13, 2008 8:57 AM

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

# re: Redirecting the Users to different pages based on there roles@ Monday, May 26, 2008 11:41 AM

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

by luciano

# re: Redirecting the Users to different pages based on there roles@ Monday, May 26, 2008 1:50 PM

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

by anas

# re: Redirecting the Users to different page based on there roles@ Tuesday, September 22, 2009 12:39 AM

Hi,

it's pride and glory to develop first webpage using own hands :)

What do you think?

http://www.sweerbhob.net

Cheers!

Leave a Comment

(required) 
(required) 
(optional)
(required)