ASP.NET MVC Membership Roles

半城伤御伤魂 提交于 2019-12-06 11:19:44
Mark

ASP.NET's Membership provider only supports roles out of the box. It doesn't support tasks or operations. However it is relatively easy to create a custom Role Provider to meet just about any need.

For a good start check out 'Implementing a Role Provider' at http://msdn.microsoft.com/en-us/library/ie/8fw7xh74.aspx . You can also find a sample Role Provider at http://msdn.microsoft.com/en-us/library/ie/tksy7hd7.aspx .

ASP.NET Membership only supports Roles, no tasks or operations.

You can use attributes to signify which operations are allowed for which roles, like so:

[Authorize(Roles="Administrator")]
public ViewResult Edit(int id)
{
    return View("Edit");
}

Or your code can do checking using the IsInRole method:

if (User.IsInRole("Administrator"))
{
    ...
}

Good luck!

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!