我的 WebApi 过滤器方法OnActionExecuted
被调用了两次。我的过滤器(我让它尽可能简单):
public class NHibernateActionFilter : ActionFilterAttribute
{
// [Inject]
// public ISessionFactoryProvider sessionFactoryProvider { get; set; }
public override void OnActionExecuted(HttpActionExecutedContext actionExecutedContext)
{
var a = 5;
var b = a;
//new BaseSessionProvider(sessionFactoryProvider).EndContextSession();
}
}
我的设置:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
WebApiConfig.Register(GlobalConfiguration.Configuration);
//http://stackoverflow.com/questions/9521040/how-to-add-global-asp-net-web-api-filters
FilterConfig.RegisterWebApiFilters(GlobalConfiguration.Configuration.Filters);
}
public class FilterConfig
{
public static void RegisterWebApiFilters(System.Web.Http.Filters.HttpFilterCollection filters)
{
filters.Add(new NHibernateActionFilter());
}
}
在调试器中,我OnActionExecuted
用相同的actionExecutedContext
. 为什么?
UPD
Controller
public class BankSmsController : ApiController
{
[AcceptVerbs(HttpVerbs.Get)]
public int GetTest()
{
return 1;
}
}