在过去的几天里,我一直在努力理解基于声明的授权,并且我有一个严重的问题,即如何将理论知识应用到实际的MVC网站中。
像http://www.codeproject.com/Articles/639458/Claims-Based-Authentication-and-Authorization这样的教程描述了安装和基础知识的过程,但是在如何管理声明方面却很少提及。
假设有一个简单的MVC网站,用于保存有趣驯鹿的图片。它使用Thinktecture.IdentityModel,但可能每个其他的Identitymodel都可以。假设认证已经就位并且正常工作。
假设有一个简单的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)和声明的值。但这只是声明的技术基础 - 我想知道是否有一个良好的模式来创建声明并定义用户拥有/需要什么声明。