1

要使用[Authorize], [Authorize(Roles="")],[Authorize(Users="")]属性,我应该在 MembershipProvider 和 RoleProvider 中重写哪些方法?

public class CustomMembershipProvider : MembershipProvider
{
    // which methods are required?
    ...
}

public class CustomRoleProvider : RoleProvider
{
    // which methods are required?
    ...
}

任何建议,文章,教程?

4

1 回答 1

2

您需要覆盖以下方法才能MembershipProvider正常RoleProvider工作。

public class CustomMembershipProvider : MembershipProvider
{    
   public override bool ValidateUser(string username, string password)
   {            
   }

   public override MembershipUser GetUser(string username, bool userIsOnline)
   {           
   }
}

public class CustomRoleProvider : RoleProvider
{
   public override bool IsUserInRole(string username, string roleName)
   {
   }

   public override string[] GetRolesForUser(string username)
   {
   } 
}

或者,如果您只是想让Authorize过滤器工作,您可以简单地自己创建 Principal 对象

于 2013-07-01T16:34:41.287 回答