使用[Authorize]而不使用SimpleMembershipProvider [英] Using [Authorize] without SimpleMembershipProvider
本文介绍了使用[Authorize]而不使用SimpleMembershipProvider的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
有没有办法使用...
Is there a way to use...
[Authorize(Roles: "Administrator")]
public class SomeController : Controller
{
...
}
...使用我自己的角色
数据库表,而不使用 SimpleMembershipProvider
?
...with my own Roles
database table, without using SimpleMembershipProvider
?
我的用户
和角色
模型类:
[Table("Users")]
public class UserModel
{
[Key]
public Int32 ID { get; set; }
[Required]
public String Name { get; set; }
[Required]
public String Password { get; set; }
[Required]
public virtual RoleModel Role { get; set; }
}
[Table("Roles")]
public class RoleModel
{
[Key]
public Int32 ID { get; set; }
[Required]
public String Name { get; set; }
public virtual ICollection<UserModel> Users { get; set; }
}
有人有同样的问题吗?
推荐答案
您应该通过继承 AuthorizeAttribute $来创建自己的
授权
c $ c> class
You should create your own Authorize
attribute by inheriting from AuthorizeAttribute
class
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
}
然后你可以配置它,但是你喜欢。
Then you can configure it however you like.
另外您可以在Stackoverflow上查看这些问题:
Also you can take a look at these questions on Stackoverflow:
- Custom Authorize Attribute
- ASP.NET MVC 4 Custom Authorize Attribute with Permission Codes (without roles)
这篇关于使用[Authorize]而不使用SimpleMembershipProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文