1

I'm using WebApi for a rest service. I need to have every request hit a inbound filter/action (to price the request) and hit a outbound filter/action (to bill the results). About a month ago I came across the term but I can't see to recall it. Something like "PostAction" or "PostFilter". Can anyone point me in the correct direction?

4

1 回答 1

1

如果您查看此链接Filtering in ASP.NET MVC,他们有一个如何将自定义过滤器attribute应用于控制器的示例,该控制器应用于所有Action方法。

这是链接中的代码示例...

[HandleError]
public class HomeController : Controller
{
    public ActionResult Index()
    {
        ViewData["Message"] = "Welcome to ASP.NET MVC!";

        return View();
    }

    public ActionResult About()
    {
        return View();
    }
}

您可以看到添加到控制器的自定义过滤器。

在您的场景中,IActionFilter可能有用,它有两个OnActionExecuted& OnActionExecuting

看看如何添加全局 ASP.Net Web Api 过滤器?寻求有关 WebAPI 的帮助。

于 2013-09-23T20:40:25.240 回答