现在我正在尝试详细了解 asp.net mvc 身份验证的工作原理。据我了解,FormsAuthenticationModule 检查 cookie 并填充 HttpContext.User。但我找不到为我的应用程序注册 FormsAuthenticationModule 的位置?
最佳答案
它继承自根web.config。例如,如果您在 x64 计算机上安装了 .NET 4,请打开 C:\Windows\Microsoft.NET\Framework64\v4.0.30319\Config\web.config
。在 system.web
部分中,您会发现已注册以下模块:
<httpModules>
<add name="OutputCache" type="System.Web.Caching.OutputCacheModule" />
<add name="Session" type="System.Web.SessionState.SessionStateModule" />
<add name="WindowsAuthentication" type="System.Web.Security.WindowsAuthenticationModule" />
**<add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />**
<add name="PassportAuthentication" type="System.Web.Security.PassportAuthenticationModule" />
<add name="RoleManager" type="System.Web.Security.RoleManagerModule" />
<add name="UrlAuthorization" type="System.Web.Security.UrlAuthorizationModule" />
<add name="FileAuthorization" type="System.Web.Security.FileAuthorizationModule" />
<add name="AnonymousIdentification" type="System.Web.Security.AnonymousIdentificationModule" />
<add name="Profile" type="System.Web.Profile.ProfileModule" />
<add name="ErrorHandlerModule" type="System.Web.Mobile.ErrorHandlerModule, System.Web.Mobile, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" />
<add name="ServiceModel" type="System.ServiceModel.Activation.HttpModule, System.ServiceModel.Activation, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" />
<add name="UrlRoutingModule-4.0" type="System.Web.Routing.UrlRoutingModule" />
<add name="ScriptModule-4.0" type="System.Web.Handlers.ScriptModule, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35"/>
</httpModules>
ASP.NET 将其与它在文件系统层次结构中找到的所有 web.config
文件合并,以便应用程序默认启用所有模块。
关于asp.net - FormsAuthenticationModule 在哪里注册?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20163911/