now I enabled roles, but I have the same problem, when a user logs in the user depends to a role. How can I configure that role1 should be redirected to side1 and role2 should be redirected to side2?
Sub Login1_LoggedIn(ByVal sender
As
Object,
ByVal e
As System.EventArgs)
If (Roles.IsUserInRole("role1")) =
True Then
Response.Redirect(
"page1.aspx")
Else
If (Roles.IsUserInRole("role2")) =
True Then
Response.Redirect(
"page2.aspx")
Else
Response.Redirect(
"page3.aspx")
End If
End If
End Sub
But now always the page3.aspx is shown. Not the page1 or page2. I read that the result will only after a postback be true. How can I realize a pageback before this sub is running?
it is rediredcted to signup.aspx page,its ok,but when i use the
signup.aspx page it always redirected to root default.aspx page which i have not coded like this,
http://localhost:2598/upload2/default.aspx
chris_koehne
Member
8 Points
59 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 09:09 PM|LINK
Luis,
now I enabled roles, but I have the same problem, when a user logs in the user depends to a role. How can I configure that role1 should be redirected to side1 and role2 should be redirected to side2?
Chris
LuisE
Member
313 Points
89 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 09:18 PM|LINK
Have you assigned user1 to role1?
If so you do this:
if(Roles.IsUserInRole("User1", "role1"))
Response.Redirect("Page1.aspx")
...
chris_koehne
Member
8 Points
59 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 09:35 PM|LINK
Luis,
I had done it like that:
Protected
Sub Login1_LoggingIn(ByVal sender As Object, ByVal e As System.Web.UI.WebControls.LoginCancelEventArgs) If (Roles.IsUserInRole("user1", "role1")) ThenResponse.Redirect(
"side1.aspx")
Else If (Roles.IsUserInRole("user2", "role2")) ThenResponse.Redirect(
"side.aspx") ElseResponse.Redirect(
"side3.aspx") End If End IfBut no matter which user and pass I try I will always be forwarded to page1? What I am doing wrong now?
Chris
LuisE
Member
313 Points
89 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 09:49 PM|LINK
Chris,
First you are using the wrong event. Use the LoggedIn Event.
Then do this:
protected void Login1_LoggedIn(object sender, EventArgs e)
{
if (Roles.IsUserInRole("role1"))
Response.Redirect("Page1.aspx");
else if (Roles.IsUserInRole("role2"))
Response.Redirect("Page2.aspx");
}
-Luis
chris_koehne
Member
8 Points
59 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 10:14 PM|LINK
Luis,
my app is in VB, so I changed your code to:
Protected
Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) If (Roles.IsUserInRole("role1")) = True ThenResponse.Redirect(
"page1.aspx") Else If (Roles.IsUserInRole("role2")) = True ThenResponse.Redirect(
"page2.aspx") ElseResponse.Redirect(
"page3.aspx") End If End If
End SubBut now always the page3.aspx is shown. Not the page1 or page2. I read that the result will only after a postback be true. How can I realize a pageback before this sub is running?
Chris
LuisE
Member
313 Points
89 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 10:39 PM|LINK
Try replacing this : Roles.IsUserInRole("role1")
with this : Roles.IsUserInRole(((System.Web.UI.WebControls.Login)sender).UserName, "role1");
chris_koehne
Member
8 Points
59 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 10:52 PM|LINK
Hey Luis,
we made it ;-)). But it was easier than with your one. The following code works now perfectly:
Protected
Sub Login1_LoggedIn(ByVal sender As Object, ByVal e As System.EventArgs) If Roles.IsUserInRole(Login1.UserName, "role1") = True ThenResponse.Redirect(
"side1.aspx") Else If (Roles.IsUserInRole(Login1.UserName, "role2")) = True ThenResponse.Redirect(
"side2.aspx") ElseResponse.Redirect(
"side3.aspx") End If End If
End SubMany thanks for all your help!!!
Wish you a nice day, Chris
LuisE
Member
313 Points
89 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 11:19 PM|LINK
Chris,
I am glad it worked :).
-Luis
chris_koehne
Member
8 Points
59 Posts
Re: User Login redirect to differnet pages
Feb 26, 2007 11:55 PM|LINK
shailesh_tha...
Member
66 Points
28 Posts
Re: User Login redirect to differnet pages
Jul 10, 2008 12:18 PM|LINK
hi,
i also want to redirect user based on my role
but it is not working and for the admin role it is always redrected to root's default.aspx.
when i directly access my admin's any page for example http://localhost:2598/upload2/SignIn.aspx?ReturnUrl=%2fupload2%2fAdmin%fAddNews.aspx
it is rediredcted to signup.aspx page,its ok,but when i use the signup.aspx page it always redirected to root default.aspx page which i have not coded like this, http://localhost:2598/upload2/default.aspx
my signup.aspx.cs file is
public
partial class SignIn : System.Web.UI.Page{
protected void Page_Load(object sender, EventArgs e){
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e){
Login Login2 = (Login)LoginView1.FindControl("Login1");if (Membership.ValidateUser(Login2.UserName, Login2.Password)){
FormsAuthentication.SetAuthCookie(Login2.UserName, Login2.RememberMeSet); Response.Redirect(FormsAuthentication.GetRedirectUrl(Login2.UserName, Login2.RememberMeSet));}
}
protected void Login1_LoggingIn(object sender, LoginCancelEventArgs e){
}
protected void Login1_LoggedIn(object sender, EventArgs e){
Login Login2 = (Login)LoginView1.FindControl("Login1"); if (Roles.IsUserInRole(Login2.UserName,"Admin")==true){
Response.Redirect("../Admin/AddNews.aspx");}
}
}
so please tell me how can i redirect to admin folder's AddNews.aspx page from my login page?