【问题标题】:MVC Forms authentication breaks no longer functional after move to Server 2016迁移到 Server 2016 后,MVC 表单身份验证中断不再起作用
【发布时间】:2019-01-16 06:54:15
【问题描述】:

我正在处理运行 IIS 7.5 的 Windows Server 2008R2 到运行 IIS 10 的 Windows 2016 Server 之间的应用程序传输。该应用程序的登录系统使用带有 LDAP 的表单身份验证来允许用户登录并进行更改。用户可以在 2008R2 服务器上毫无问题地登录,创建必要的 cookie 以供使用。但是,在 2016 Server 上,登录系统身份验证似乎中断了。似乎创建了 cookie,但创建 cookie 后系统似乎无法找到用户。此外,在不运行任何登录进程的特定页面上,应用程序似乎正在使用 Windows 身份验证,而不是明确告知要使用的表单身份验证。 web.config 中的应用程序设置明确告诉它使用表单而不是 Windows 身份验证。

应用程序的 web.config 包含连接字符串的以下信息:

<connectionStrings>
<add name="ADConnectionString" connectionString="LDAP://OURLDAPSYSTEM"/>
</connectionStrings>

此系统的 LDAP 项仅用于验证而非权限。

以及身份验证和成员资格:

<system.web>
  <authentication mode="Forms">
    <forms name=".ADAuthCookie" loginUrl="~/" timeout="60" slidingExpiration="true" protection="All"/>
  </authentication>
  <membership defaultProvider="ADMembershipProvider">
    <providers>
      <add name="ADMembershipProvider" type="System.Web.Security.ActiveDirectoryMembershipProvider" connectionStringName="ADConnectionString" attributeMapUsername="sAMAccountName"/>
    </providers>
  </membership>
</system.web>

在执行登录过程的控制器中:

userLoginSuccess = Membership.ValidateUser(model.UserName, model.Password);
//Make call to another DB to check permissions for usage
FormsAuthentication.SetAuthCookie(model.UserName, true);

在服务器上的 IIS 上,应用程序的身份验证显示如下: Authentication for the application

而整个网站的身份验证显示如下:Authentication for the Site

其中的每一个都与 Windows 2008R2 服务器上已存在的内容相匹配。

任何人都知道在 Windows 2016 服务器上会发生什么变化,这会阻止身份验证与 2008R2 一样工作吗?如果是这样,我将如何解决这个问题?

【问题讨论】:

    标签: c# ldap forms-authentication windows-server-2016 iis-10


    【解决方案1】:

    同样的事情 - 只是花了一整天的时间看着这个。

    找到这个:https://www.itnota.com/enable-secure-httponly-cookies-iis/

    <system.web>
      ...
      <httpCookies httpOnlyCookies="true" requireSSL="false" />
      ...
    </system.web>
    

    我们将其添加到 web.config 中并且它起作用了。

    【讨论】:

    • 请将解决方案包含为代码 sn-p 而不是图像。谢谢。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-06-12
    • 2019-02-17
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多