在MVC3 Web应用程序中将表单身份验证更改为Windows身份验证需要哪些步骤?

时间:2015-10-15 15:52:32

标签: asp.net-mvc-3 authentication windows-authentication

我正在开发一个遗留MVC3应用程序,该应用程序使用Forms身份验证和SQLMembership Provider来授权用户访问。它具有以下配置:

<authentication mode="Forms">
  <forms loginUrl="~/Account/Login" timeout="2880" />
</authentication>
<membership>
  <providers>
    <clear />
    <add name="AspNetSqlMembershipProvider" type="System.Web.Security.SqlMembershipProvider" connectionStringName="ApplicationServices" enablePasswordRetrieval="true" enablePasswordReset="true" requiresQuestionAndAnswer="false" requiresUniqueEmail="true" maxInvalidPasswordAttempts="5" minRequiredPasswordLength="3" minRequiredNonalphanumericCharacters="0" passwordAttemptWindow="10" applicationName="/TimeSheets" passwordFormat="Clear" />
  </providers>
</membership>
<profile inherits="Timesheets.Services.UserProfile">
  <providers>
    <clear />
    <add name="AspNetSqlProfileProvider" type="System.Web.Profile.SqlProfileProvider" connectionStringName="ApplicationServices" applicationName="/TimeSheets" />
  </providers>
</profile>
<roleManager enabled="true">
  <providers>
    <clear />
    <add name="AspNetSqlRoleProvider" type="System.Web.Security.SqlRoleProvider" connectionStringName="ApplicationServices" applicationName="/TimeSheets" />
    <add name="AspNetWindowsTokenRoleProvider" type="System.Web.Security.WindowsTokenRoleProvider" applicationName="/TimeSheets" />
  </providers>
</roleManager>

如果我使用Windows身份验证创建新的MVC应用程序,则此配置似乎将替换为以下配置:

<authentication mode="Windows" />
<authorization>
  <deny users="?" />
</authorization>

我尝试过更改旧版MVC网站的配置以使用这种新的身份验证模式,但是无法进行身份验证(我收到错误消息“401.2:未授权:登录因服务器配置而失败。”)

然而,新的Web项目正确运行并进行身份验证(因此它不是AD或本地权限问题)

我曾想过尝试将所有遗留代码放入新项目中,但它相当庞大而且复杂,并且在新网站中重新排列所有内容可能非常耗时。

我希望更改Auth模型应该更简单,更少侵入 - 但是我需要执行哪些额外步骤来配置旧版网站以进行Windows身份验证?

1 个答案:

答案 0 :(得分:0)

我的配置更改中缺少的部分是在.proj文件中。这是因为在Visual Studio中使用IIS Express。

要使Windows Auth在IIS Express中工作以进行调试,您需要在项目设置中对其进行配置:

行:

<IISExpressAnonymousAuthentication />
<IISExpressWindowsAuthentication />

需要替换为:

<IISExpressAnonymousAuthentication>disabled</IISExpressAnonymousAuthentication>
<IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication>
相关问题