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

protected override bool AuthorizeCore(HttpContextBase httpContext)

{

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 = "****")]

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-05-25
  • 2022-12-23
  • 2021-12-12
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案