ASP.NET MVC 5 Web.config:"FormsAuthenticationModule"或"FormsAuthentication"

wir*_*_in 43 asp.net forms-authentication iis-8 owin asp.net-mvc-5

好吧,这不是什么大不了的事,但它让我烦恼,我不能放手.

所以我使用MVC 5.1与.NET 4.5.1和OWIN身份验证.因此,当您创建新的MVC 5项目时,以下内容会自动添加到Web.config中以删除表单身份验证http模块,因为在使用OWIN中间件时不再需要它:

<system.webServer>
    <modules>
        <remove name="FormsAuthenticationModule" />
    </modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

现在,因为我们正在删除模块,这意味着它之前已添加,所以这里是注册此http模块的条目C:\Windows\Microsoft.NET\Framework\v4.0.30319\Config\web.config:

<httpModules>
    <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" />
</httpModules>
Run Code Online (Sandbox Code Playgroud)

这里是C:\Windows\System32\inetsrv\config\applicationHost.configIIS 8.5 的条目,告诉我的应用程序使用该模块:

<system.webServer>
    <modules>
        <add name="FormsAuthentication" type="System.Web.Security.FormsAuthenticationModule" preCondition="managedHandler" />
    </modules>
</system.webServer>
Run Code Online (Sandbox Code Playgroud)

因此,在应用程序级别自动添加到我的Web配置的名称属性为"FormsAuthenticationModule",而两个服务器级别/ asp.net级别配置文件中的条目使用名称属性"FormsAuthentication".那么这里发生了什么?在我看来,由于name属性不匹配,因此不会删除该模块.我只是认为这是一个错字,但在网上搜索后,每个人似乎都在应用程序web.config中使用"FormsAuthenticationModule".这是最新版本的asp.net/iis的最新变化还是我错过了什么?

Bro*_*len 27

你是对的 - 这是模板中的拼写错误.


Aar*_*man 7

这个"拼写错误"的一个主要副作用是它会使FormsAuthentication导致忽略owin的loginpath并调用经过身份验证的页面转到/login.aspx