你的位置:首页 > 软件开发 > ASP.net > MVC权限控制

MVC权限控制

发布时间:2015-07-24 16:00:04
基本方法是重写AuthorizeAttribute类的AuthorizeCore方法protected override bool AuthorizeCore(HttpContextBase httpContext) { string currentRole = ...

基本方法是重写AuthorizeAttribute类的AuthorizeCore方法

protected override bool AuthorizeCore(HttpContextBase httpContext)

{

get='_blank'>string currentRole = GetRole(httpContext.User.Identity.Name);

if (Roles.Contains(currentRole))

return true;

return base.AuthorizeCore(httpContext);

}

 

private string GetRole(string name)

{

Model1 db = new Model1();

student newstudent = db.Students.First(m => m.name == name);

return newstudent.name;

}

 

登录的时候需要写入name信息

FormsAuthentication.SetAuthCookie(stu.name, false);

 

最后在需要控制的action前加上

[MyAuthAttribute2(Roles = "****")]


原标题:MVC权限控制

关键词:mvc

mvc
*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。