首页 > 解决方案 > 与 Azure AD 集成在 Azure IAAS 上托管的 .net 应用程序的相同站点问题

问题描述

我们拥有托管在 Azure IAAS 环境中的带有 Azure AD 集成的 ASP.NET Webforms 和 ASP.NET MVC 应用程序。由于最近的 Chrome 安全版本 > 80 及更高版本,大多数应用程序开始崩溃。请在下面找到框架版本

  1. 所有应用程序都在 4.5.2 上运行,并且还依赖于 NuGet 包

    为了解决这个问题,我们探索了以下选项。由于我们有多个选项,因此我们需要专家就哪个选项最适合带有 Azure AD 集成的 APPS 提供意见。

  2. system.webServer标签下设置 IIS 重写规则。它无需任何代码更改和框架升级即可工作

<rewrite>
  <outboundRules>
    <preConditions>
      <!-- Checks User Agent to identify browsers incompatible with SameSite=None -->
      <preCondition name="IncompatibleWithSameSiteNone" logicalGrouping="MatchAny">
        <add input="{HTTP_USER_AGENT}" pattern="(CPU iPhone OS 12)|(iPad; CPU OS 12)" />
        <add input="{HTTP_USER_AGENT}" pattern="(Chrome/5)|(Chrome/6)" />
        <add input="{HTTP_USER_AGENT}" pattern="( OS X 10_14).*(Version/).*((Safari)|(KHTML, like Gecko)$)" />
      </preCondition>
    </preConditions>
    <!-- Adds or changes SameSite to None for the session cookie -->
    <!-- Note that secure header is also required by Chrome and should not be added here -->
    <rule name="SessionCookieAddNoneHeader">
      <match serverVariable="RESPONSE_Set-Cookie" pattern="(.*)(SameSite=.*)?"  />
        <conditions logicalGrouping="MatchAll" trackAllCaptures="false">
        <add input="{HTTP_HOST}" pattern="localhost" negate="true" />
          </conditions>
      <action type="Rewrite" value="{R:1}; SameSite=None; Secure" />
    </rule>
    <!-- Removes SameSite=None header from all cookies, for most incompatible browsers -->
    <rule name="CookieRemoveSameSiteNone" preCondition="IncompatibleWithSameSiteNone">
      <match serverVariable="RESPONSE_Set-Cookie" pattern="(.*)(SameSite=.*)?"  />
      <action type="Rewrite" value="{R:1}" />
    </rule>
  </outboundRules>
</rewrite>
  1. 我们尝试将框架版本更新到 4.7.2 和相应的 nuget 包的另一个选项。它需要在 OpenIDconnect 上更改代码。我们尝试根据 Microsoft 提供的文档来实现相同的功能

https://docs.microsoft.com/en-us/azure/active-directory/develop/howto-handle-samesite-cookie-changes-chrome-browser?tabs=dotnet

  1. 第三是尝试将框架版本降级到 4.5.0 和相应的 NuGet 包。此选项也可以正常工作。

标签: asp.netazuregoogle-chromeazure-active-directorysamesite

解决方案


推荐阅读