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();
}
}

 

 

 

posted @ 2012-02-03 16:17  南阳·源  阅读(341)  评论(0编辑  收藏  举报