Asp.Net MVC3(二)-过滤器定义
定义过滤类:
public class TestFilter : ActionFilterAttribute
{
/// <summary>
/// 行为执行前
/// </summary>
/// <param name="filterContext"></param>
public override void OnActionExecuting(ActionExecutingContext filterContext)
{
//ToDoing
if (filterContext.ActionDescriptor.ActionName.ToLower() == "testList".ToLower())
{
if (true)
{
filterContext.HttpContext.Response.Write("您没有权限操作!");
filterContext.HttpContext.Response.End();
}
}
base.OnActionExecuting(filterContext);
}
}
控制器中使用:
[TestFilter]
public class AuditPayExpenseController : Controller
{
public ActionResult testList(int? pagerIndex, FormCollection collenct)
{
return View();
}
}