嘿嘿!今天看见同事在搞MVC3的权限验证,以前不是很懂MVC3,自己研究了一下。希望对跟我一样的菜鸟童鞋有点点点帮助吧!
 
public class RoleFilter : FilterAttribute, IAuthorizationFilter
{
 
#region IAuthorizationFilter 成员
 
/// <summary>
/// 产生随机数判断是否具有权限访问
/// </summary>
/// <param name="filterContext"></param>
public void OnAuthorization(AuthorizationContext filterContext)
{
Random random = new Random();
int i = random.Next(0, 10);
if (i > 3)
{
filterContext.Result = new RedirectResult(ConfigurationManager.AppSettings["Url"] + "/Error/Index/" + i);
}
}
 
#endregion
 
}

 

 

下面是在Action上面加上 就可以验证了:

 

[RoleFilter()]
public ActionResult Del(int id)
{
AlbumModels albumModels = GetModels();
albumModels.DelAlbum(id);
return View();
}

相关文章:

  • 2021-06-08
  • 2021-09-14
  • 2021-09-12
  • 2021-05-15
  • 2022-12-23
  • 2021-05-26
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-10-29
  • 2021-09-14
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案