刚刚花了很多时间筛选关于这个问题的相互矛盾的建议,并认为我会发布我的解决方案。
我的环境是 .NET 4.5,Visual Studio 2012,在 MVC 4 应用程序上工作。我像过去一样创建了一个 Http 模块,并将其添加到 Web.config 中,如下所示:
<configuration>
<system.web>
<httpModules>
<add name="MyModule" type="Services.MyModule, Services" />
</httpModules>
</system.web>
</configuration>
但是,应用程序从未调用模块的 Init()。最终,我发现模块应该改为 inside <system.webServer>
,元素命名<modules>
为<httpModules>
,如下所示:
<configuration>
<system.webServer>
<modules>
<add name="MyModule" type="MyModule" type="Services.MyModule, Services" />
</modules>
</system.webServer>
</configuration>
重新运行应用程序,它按预期调用了 Init()。FWIW,带有方向的页面在这里:http: //msdn.microsoft.com/en-us/library/ms227673.aspx
高温高压