Redirect to another page according to their roles

I need help from you guys. So there are two roles in my system. Administrator and users. I am using a control to login. How can I redirect these two roles to another page? I use member and form authentication. I would appreciate it if you could help me. Thanks:)

+4
source share
4 answers

Process the Login OnLoggedIn control. In this case, determine the current user role. This can be done as follows ("LoginUser" below represents your login control):

string[] userRole = Roles.GetRolesForUser(LoginUser.UserName); 

http://msdn.microsoft.com/en-us/library/system.web.security.roleprincipal.getroles%28v=vs.100%29.aspx

Then use role-based Response.Redirect to send them to the desired destination.

+4
source

I realized that right now. The first thing you need to do is go to the event in the login properties of the control system, double click on the loggedIn line, it will direct you to the cs page. Then what you need to do is

 protected void Login1_LoggedIn(object sender, EventArgs e) { { if (Roles.IsUserInRole(Login1.UserName, "Admin")) Response.Redirect("~/Admin/Default.aspx"); else if (Roles.IsUserInRole(Login1.UserName, "User")) Response.Redirect("~/User/Default.aspx"); } } 

Then be sure to specify the destination URL of the login control for the URL so that you want to redirect the user after logging in

+3
source

This will redirect the user to the appropriate pages depending on their roles.

 protected void Login1_Authenticate(object sender, AuthenticateEventArgs e) { if (Membership.ValidateUser(Login1.UserName, Login1.Password)) { if (Roles.IsUserInRole(Login1.UserName, "Admin")) { Response.Redirect("~/Admin/Default.aspx"); } else if (Roles.IsUserInRole(Login1.UserName, "User")) { Response.Redirect("~/User/Default.aspx"); } } } 

Thanks.

+1
source

This code works:

 Try If Membership.ValidateUser(Login1.UserName, Login1.Password) Then If Roles.IsUserInRole(Login1.UserName, "administrasi") Then Response.Redirect("~/administrasi/Default.aspx") ElseIf Roles.IsUserInRole(Login1.UserName, "client") Then Response.Redirect("~/client/Default.aspx") Else Response.Redirect("~/user/Default.aspx") End If End If Catch ex As Exception End Try 
+1
source

Source: https://habr.com/ru/post/1397937/


All Articles