根据角色重定向到其他页面

发布于 2025-01-08 10:19:14 字数 120 浏览 5 评论 0原文

我需要你们的帮助。所以,在我的系统上,有 2 个角色。管理员和用户。我使用登录控制来使他们能够登录系统。我怎样才能使这两个角色重定向到不同的页面?我正在使用会员资格和表单身份验证。如果您能给我一些帮助,我将不胜感激。谢谢 :)

i need help from u guys here. So, on my system, there are 2 roles. Admin and users. I use login control to enable them to login to the system. How can i make these two roles redirect to different page? I am using membership and form authentication. I would appreciate if you could give some help to me. Thank you :)

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

听,心雨的声音 2025-01-15 10:19:14

处理登录控件的“OnLoggedIn”事件。在这种情况下,确定当前用户的角色。可以按如下方式完成(下面的“LoginUser”代表您的登录控制):

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

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

然后使用 Response.Redirect根据角色将它们发送到正确的目的地。

Handle the Login controls "OnLoggedIn" event. In this event, determine the current users role. That 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 Response.Redirect based on the role to send them to the correct destination.

优雅的叶子 2025-01-15 10:19:14

我现在就明白了。您需要做的第一件事是,转到控件中登录属性的事件,双击loggedIn行,它将引导您进入cs页面。然后,您需要做的是

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");
    }
}

然后不要忘记将登录控件的目标 URL 设置为您希望用户在登录后重定向的 url

I got it right now. The first thing u need to do is, go to event at the properties of the login in control, the double click at loggedIn row, the it will direct you at cs page. Then, what u 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 dont forget to set the destination URL of the login control to url that u want user redirect after login

莫多说 2025-01-15 10:19:14

这将根据用户的角色将用户重定向到相应的页面。

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");
            }               
        }
    }

谢谢。

This will redirect the user to respective pages based 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.

浮华 2025-01-15 10:19:14

这段代码的工作原理:

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

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
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文