剛剛花了很多時間篩選這個問題的矛盾意見,並認爲我會發布我的解決方案。在.NET 4.5中沒有調用HttpModule
我的環境是使用MVC 4應用程序的.NET 4.5,Visual Studio 2012。我創建了一個HTTP模塊就像我在過去做這些,並增加它的Web.config像這樣:
<configuration>
<system.web>
<httpModules>
<add name="MyModule" type="Services.MyModule, Services" />
</httpModules>
</system.web>
</configuration>
但是,應用程序不會被調用模塊的init()。最後,我發現諮詢該模塊應該改爲內<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
HTH
你應該在2個部分分割你的問題:一個問題,你的答案 – cheesemacfly
在<添加行中不能有兩種'類型'。這在語法上不正確,不會編譯。我很驚訝,這甚至工作 – Fandango68