我的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); //https://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()); } }
在调试器中,我使用相同的actionExecutedContext捕获OnActionExecuted两次.为什么?
UPD
Controller public class BankSmsController : ApiController { [AcceptVerbs(HttpVerbs.Get)] public int GetTest() { return 1; } }