这里我写了简单的Actioon Filter As
public class ActionFilter:ActionFilterAttribute
{
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
Trace.WriteLine(string.Format("Action Method {0} executing at {1}",actionExecutedContext.ActionContext.ActionDescriptor, DateTime.Now.ToShortDateString()), "Web API Logs");
}
public override void OnActionExecuting(System.Web.Http.Controllers.HttpActionContext actionContext)
{
Trace.WriteLine(string.Format("Action Method {0} executed at {1}",actionContext.ActionDescriptor.ActionName, DateTime.Now.ToShortDateString()));
}
在WebApi中
[ActionFilter]
public IHttpActionResult GetData()
{
}
这里它前后工作但我不明白为什么这个过滤器进入图片
答案 0 :(得分:1)
Action过滤器主要用于在Action执行之前和之后执行某些逻辑。
让我们考虑两个场景:
有关过滤器的详细信息,请查看以下链接: Action Filters