2010-11-10 114 views
2

有一個遺留應用程序,並從那裏調用我的MVC應用程序。 我打算使用自定義httpmodule [AuthenticationModule類繼承IHttpModule]。在初始化,我迷上了的BeginRequest,做我FormAuthenication東西...如何通過自定義httpmodule進行MVC身份驗證

 private void Application_BeginRequest(Object source, EventArgs e) { 

     // Do my own authetication and issue FormAuthentication Ticket 
    } 

在web.config中:

<system.webServer> 
    <validation validateIntegratedModeConfiguration="false"/> 
    <modules runAllManagedModulesForAllRequests="true"> 
     <add name="AuthenticationModule" type="RealProperty.LegacySecurity.AuthenticationModule, RealProperty.LegacySecurity" preCondition="ManagedHandler"/> 
    </modules> 

但我AuthenticationModule從來沒有火調試... (1)可任何人解釋爲什麼它沒有被調用? (2)在BeginRequest中進行身份驗證是否正確?

回答

2

確保您在Web.config文件中有兩個部分:

<system.web> 
    <httpModules> 
    <add name="MyAuthenticationModule" type="Ns.To.MyAuthenticationModule, MyAssembly" /> 
    </httpModules> 
</system.web> 

<system.webServer> 
    <modules runAllManagedModulesForAllRequests="true"> 
    <add name="MyAuthenticationModule" type="Ns.To.MyAuthenticationModule, MyAssembly" /> 
    </modules> 
</system.webServer> 
相關問題