【问题标题】:What steps are required to change Forms Authentication over to Windows Authentication in an MVC3 web application?在 MVC3 Web 应用程序中将表单身份验证更改为 Windows 身份验证需要哪些步骤?
【发布时间】:2016-01-14 04:20:03
【问题描述】:

我正在开发一个旧版 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.: Unauthorized: Logon failed due to server configuration.”)

但是新的 Web 项目可以正确运行和验证(因此它不是 AD 或本地权限问题)

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

我希望更改身份验证模型应该更简单且干扰更少 - 但是我需要执行哪些额外步骤来配置旧站点以进行 Windows 身份验证?

【问题讨论】:

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


    【解决方案1】:

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

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

    线条:

    <IISExpressAnonymousAuthentication />
    <IISExpressWindowsAuthentication />
    

    需要替换为:

    <IISExpressAnonymousAuthentication>disabled</IISExpressAnonymousAuthentication>
    <IISExpressWindowsAuthentication>enabled</IISExpressWindowsAuthentication>
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2013-10-30
      • 2012-03-15
      • 1970-01-01
      • 2014-01-26
      • 2023-03-22
      • 1970-01-01
      • 2013-09-25
      • 1970-01-01
      相关资源
      最近更新 更多