Is there a way to add an httpModule when webApi is running with the HttpSelfHostServer?

為{幸葍}努か 提交于 2019-12-12 16:19:07

问题


I have a MVC4 webapi controller. It has no parameter-less constructors. So, i use Windsor dependency resolver and everything is fine when work under System.Web.Http.WebHost. But, when I try to use HttpSelfHostServer, i get the exception message:

Looks like you forgot to register the http module Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule To fix this add <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" /> to the <httpModules> section on your web.config. If you plan running on IIS in Integrated Pipeline mode, you also need to add the module to the <modules> section under <system.webServer>. Alternatively make sure you have Microsoft.Web.Infrastructure, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35 assembly in your GAC (it is installed by ASP.NET MVC3 or WebMatrix) and Windsor will be able to register the module automatically without having to add anything to the config file. Obviously, the windsor di cannot register his HttpModule. I've tried to add

<system.web> <httpModules> <add name="PerRequestLifestyle" type="Castle.MicroKernel.Lifestyle.PerWebRequestLifestyleModule, Castle.Windsor" /> </httpModules> </system.web>

in my app.config, no luck. Tried the WebActivator to use PreApplicationStart method with no luck as well. Is there any way to add a httpModule for self-hosted webapi app?


回答1:


HttpModules cannot be used when self-hosting. They are ASP.NET specific features.



来源:https://stackoverflow.com/questions/11831932/is-there-a-way-to-add-an-httpmodule-when-webapi-is-running-with-the-httpselfhost

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!