首页 文章

ASP.NET基于角色重定向用户

提问于
浏览
1

我希望应用程序根据用户的角色将用户重定向到其他主页 . 它目前使用以下IF为2个用户工作?

If Request.IsAuthenticated AndAlso User.IsInRole("Staff") = True Then
        Response.Redirect("~/About.aspx")
    ElseIf Request.IsAuthenticated AndAlso User.IsInRole("HR") = False Then
        Response.Redirect("~/HR\HRCompanyNavigation.aspx")
    End If

如何让这个工作超过2个用户角色?

1 回答

  • 3

    像这样的东西?这可能适用于更简单的方案 . 但是你应该记住,如果用户有多个角色,这是一个弱结构 .

    If Request.IsAuthenticated AndAlso User.IsInRole("Staff") = True Then
                Response.Redirect("~/About.aspx")
            ElseIf Request.IsAuthenticated AndAlso User.IsInRole("HR") = True Then
                Response.Redirect("~/HR\HRCompanyNavigation.aspx")
            ElseIf Request.IsAuthenticated AndAlso User.IsInRole("ThirdRole") = True Then
                Response.Redirect("~/ThirdFolder\ThirdPage.aspx")
        End If
    

相关问题