[原创]基于角色的Roles
在Global.asax中实现基于角色的Roles
Sub Application_AuthenticateRequest(ByVal sender As Object, ByVal e As EventArgs)
' 尝试对使用进行身份验证时激发
If Request.IsAuthenticated Then
If User.Identity.Name.ToLower = "a" Then
Dim roles() As String = {"administrator", "normal"}
Context.User = New GenericPrincipal(User.Identity, roles)
End If
End If
End Sub
那么在要判断的页面中就可以写
If User.IsInRole("administrator") Then
Response.Write("you are an administrator")
Else
Response.Write("you are a Normal User")
End If
那么在要判断的页面中就可以写
浙公网安备 33010602011771号