最近几天我一直在努力理解基于声明的授权,并且我有一个严重的问题将理论知识应用于现实世界的 MVC 网站。
教程如 http://www.codeproject.com/Articles/639458/Claims-Based-Authentication-and-Authorization正在描述安装过程和非常基础的知识,但很少涉及如何管理 claim 。
假设有一个简单的 MVC 网站,用于保存有趣的驯鹿图片。
它正在使用 Thinktecture.IdentityModel,但可能其他所有 Identitymodel 都会这样做。
假设身份验证已就位并正常工作。
public class ReindeerController : Controller
{
//should be accesible to whole world
public ActionResult AboutReindeers()
{}
//should be accessible to users which are supposed to add Reindeers, e.g. an "Admin" (which is a role, I know)
public ActionResult AddReindeer()
{}
//Only for the Site-owner
public ActionResult DeleteReindeer()
{}
//should be accesible to registred users
public ActionResult Index()
{}
}
所以我有一个 UserClaims 表,它存储用户 ID、作为 URL 的声明类型和声明的值。但这只是声明的技术基础 - 我想了解是否有一个好的模式来创建声明并定义用户拥有/需要的声明。
最佳答案
看看这个(旧)帖子 about claims authorization以获得概览。
然后你会发现更多细节here ,thinktecture 上还有很多其他不错的帖子。
WIF API 描述应该可以帮助您填补空白。
关于asp.net-mvc - 基于声明的授权 - 如何管理声明,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19809497/