前几天网上搜索了好久的文章,整理下MVC Authorize关于Roles,Users的权限
基于上一篇OAuth四种授权模式的实现
地址:https://mp.csdn.net/postedit/102814687
1.在API项目的 Global.asax.cs中,初始化构造方法,添加授权请求初始角色,用户方法
//构造方法
public WebApiApplication()
{
AuthenticateRequest += WebApiApplication_AuthenticateRequest;
}
//授权请求初始化角色,用户
private void WebApiApplication_AuthenticateRequest(object sender, EventArgs e)
{
HttpCookie authcookie = Context.Request.Cookies[FormsAuthentication.FormsCookieName];
if (authcookie == null || authcookie.Value == "")
return;
FormsAuthenticationTicket authticket = null;
try
{
authticket = FormsAuthentication.Decrypt(authcookie.Value);
}
catch