使用ASP.NET MVC时未触发FormsAuthenticationModule身份验证事件

使用ASP.NET MVC时未触发FormsAuthenticationModule身份验证事件,asp.net,asp.net-mvc,iis,forms-authentication,iis-7.5,Asp.net,Asp.net Mvc,Iis,Forms Authentication,Iis 7.5,我们正在使用HttpModule钩住FormsAuthenticationModule并订阅Authenticate事件。当我们使用web表单时,此事件在模块中激发。当我们使用MVC时,此事件不会触发 我已尝试在web.config中的控制器和位置上使用[Authorize]属性(尽管这不是最佳做法)尝试触发此事件,但仍然没有 该事件在使用Cassini Web服务器时会触发,但在IIS 7.5或IIS Express上不会触发。我们正在使用.NET3.5运行ASP.NETMVC2 编辑 当我们

我们正在使用HttpModule钩住FormsAuthenticationModule并订阅Authenticate事件。当我们使用web表单时,此事件在模块中激发。当我们使用MVC时,此事件不会触发

我已尝试在web.config中的控制器和位置上使用[Authorize]属性(尽管这不是最佳做法)尝试触发此事件,但仍然没有

该事件在使用Cassini Web服务器时会触发,但在IIS 7.5或IIS Express上不会触发。我们正在使用.NET3.5运行ASP.NETMVC2

编辑

当我们请求.aspx或.ashx文件时,将触发身份验证事件。如果我们请求一个无扩展文件或.css或.js,它也不会启动

新的ASP.NET MVC应用程序将为每个请求的文件触发此事件


有什么建议吗?

我不认为这是解决问题的最佳方法,但我也在使用MVC和formpages的组合,并在web.config中设置所有授权

<location path="[path]"> 
   <system.web>
     <authorization>
        <allow users="[username]" roles="[role]"/>
        <deny users="*"/>
      </authorization>
   </system.web>
</location> 

我们的web.config缺少system.webServer中modules元素的runAllManagedModulesForAllRequests=“true”。添加后,所有web请求都会从FormsAuthenticationModule接收授权事件

<system.webServer>
    ....
    <modules runAllManagedModulesForAllRequests="true">
    ....
</system.webServer>

....
....

导航到aspx页面不会测试表单身份验证是否在MVC中工作,您必须导航到路由。我看到了你的答案,这就是我的想法。我建议删除managedHandler前提条件,而不是低效的
runAllManagedModulesForAllRequests=“true”

     <remove name="FormsAuthentication"/>
     <add name="FormsAuthentication" preCondition="" type="System.Web.Security.FormsAuthenticationModule"/>

     <remove name="DefaultAuthentication"/>
     <add name="DefaultAuthentication" preCondition="" type="System.Web.Security.DefaultAuthenticationModule"/>

     <remove name="RoleManager"/>
     <add name="RoleManager" preCondition="" type="System.Web.Security.RoleManagerModule"/>

     <remove name="UrlAuthorization"/>
     <add name="UrlAuthorization" preCondition="" type="System.Web.Security.UrlAuthorizationModule"/>

     <remove name="UrlRoutingModule-4.0"/>
     <add name="UrlRoutingModule-4.0" preCondition="runtimeVersionv4.0" type="System.Web.Routing.UrlRoutingModule"/>


表单身份验证在MVC中是否正常工作?@MaxToro是。如果我已经导航到aspx页面,自定义HttpHandlder将已经运行并设置表单cookie。我尝试过此操作以查看是否有帮助,但没有。以这种方式为MVC页面配置安全性也是一种安全风险。对于个人信息,使用这种方法会形成哪些安全风险?不知道为什么它对你不起作用。@Amarplaspure我本来会的,但是SO不允许你这样做一天。嗯,我不知道,到目前为止还没有问过问题。谢谢你的回答。许多人建议关闭runAllManagedModulesForAllRequests,但不要列出大多数MVC站点工作所需的这些模块