本文介绍了使用[授权]无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; }
}
是否有人有同样的问题?
Does someone have the same problem?
推荐答案
您应该从 AuthorizeAttribute $继承创建自己的
授权
属性C $ C>类
You should create your own Authorize
attribute by inheriting from AuthorizeAttribute
class
public class CustomAuthorizeAttribute : AuthorizeAttribute
{
}
然后你就可以你喜欢的配置。
Then you can configure it however you like.
您也可以在#2这些问题一起来看看:
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)
这篇关于使用[授权]无SimpleMembershipProvider的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!