网站不断重定向到 ADFS

Website continuously redirects to ADFS

我对整个 SSO 场景还比较陌生,所以如果这看起来微不足道,请多多包涵。
我似乎遇到了一个有点奇怪的问题,我什至不确定如何开始在任何地方查找它。

我正在使用 ASP.NET MVC 中的本地选项为我的组织实施 WS-Fed ADFS,它使用 OWIN 实施整个过程。

实施工作正常,因为它适用于我电脑的 Chrome 浏览器,但不适用于其他地方。但我知道它有效,因为我能够通过 Fiddler

捕获数据

你会注意到我的网站和 ADFS 之间不断来回,即使登录成功并且检索到的数据也是正确的。
几次跳转后,我收到一个错误页面


这是我的 Web.Config

<configuration>
  <appSettings>
    <add key="webpages:Version" value="3.0.0.0" />
    <add key="webpages:Enabled" value="false" />
    <add key="ClientValidationEnabled" value="true" />
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="ida:ADFSMetadata" value="https://xyz-test.azurewebsites.net/FederationMetadata/2007-06/federationmetadata.xml" />
    <add key="ida:Wtrealm" value="https://xyz-test.azurewebsites.net/" />
  </appSettings>
  <system.web>
    <compilation debug="true" targetFramework="4.5.2" />
    <httpRuntime targetFramework="4.5.2" />
  </system.web>
  <runtime>
    <assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1">
      <dependentAssembly>
        <assemblyIdentity name="Newtonsoft.Json" culture="neutral" publicKeyToken="30ad4fe6b2a6aeed" />
        <bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Optimization" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-1.1.0.0" newVersion="1.1.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="WebGrease" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="0.0.0.0-1.5.2.14234" newVersion="1.5.2.14234" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Helpers" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.Mvc" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-5.2.3.0" newVersion="5.2.3.0" />
      </dependentAssembly>
      <dependentAssembly>
        <assemblyIdentity name="System.Web.WebPages" publicKeyToken="31bf3856ad364e35" />
        <bindingRedirect oldVersion="1.0.0.0-3.0.0.0" newVersion="3.0.0.0" />
      </dependentAssembly>
    </assemblyBinding>
  </runtime>
  <system.codedom>
    <compilers>
      <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.CSharpCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:6 /nowarn:1659;1699;1701" />
      <compiler language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.CodeDom.Providers.DotNetCompilerPlatform.VBCodeProvider, Microsoft.CodeDom.Providers.DotNetCompilerPlatform, Version=1.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" warningLevel="4" compilerOptions="/langversion:14 /nowarn:41008 /define:_MYTYPE=\&quot;Web\&quot; /optionInfer+" />
    </compilers>
  </system.codedom>
</configuration>

RouteConfig.cs

public static void RegisterRoutes(RouteCollection routes)
{
    routes.IgnoreRoute("{resource}.axd/{*pathInfo}");

    routes.MapRoute(
        name: "Default",
        url: "{controller}/{action}/{id}",
        defaults: new { controller = "Home", action = "Index", id = UrlParameter.Optional }
    );
}

家庭控制器

[Authorize]
public class HomeController : Controller
{

    public ActionResult Index()
    {
        return View((User as ClaimsPrincipal).Claims);
    }
}

我想了解如何解决这个问题。 why/how 它甚至可以在我电脑的 Chrome 浏览器上运行吗?

看起来您 运行 喜欢 。我看到您通过 http 而不是 https 访问您的应用程序。

好久没来了,但我发现了导致这个问题的原因。

这个问题以及其他一些归因于使用 OWIN 的 ADFS 登录的问题,特别是如果您使用 Microsoft 提供的默认代码,是因为 OWIN 在 .NET 4.5 中使用的默认 cookie 管理器中存在错误。

找到答案here 公平地说,它更像是一种变通方法而不是解决方案。

这基本上使用 SystemWebCookieManager 作为自定义 cookie 管理器,一切都按应有的方式工作。

此外,您还可以从 here and its dependent class can be found here 获取 SystemWebCookieManager 的代码。
注意:它看起来像是来自 Katana 项目的代码,因此请确保您也包含版权注释,并将这两个 类 包含到您的解决方案中。

从现在开始,ADFS 一切如常,不再需要更改(除非您正在做其他事情)。