[原创]基于角色的Roles

        在Global.asax中实现基于角色的Roles
    Sub Application_AuthenticateRequest(ByVal sender As ObjectByVal 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
posted on 2005-03-07 22:22  雪无止境  阅读(266)  评论(0编辑  收藏  举报