identity server4 授权成功页面跳转时遇到错误:Exception: Correlation failed. Unknown location的解决方法

一、异常信息描述

错误信息,看到这个页面是否耳熟能详担又不知道怎么解决 ,坑死个人不偿命,,,,,,,,

identity server4 授权成功页面跳转时遇到错误:Exception: Correlation failed. Unknown location的解决方法

二、处理方法

1、在web项目中增加类SameSiteCookiesServiceCollectionExtensions.cs

public static class SameSiteCookiesServiceCollectionExtensions
    {
        ///
        /// -1 defines the unspecified value, which tells ASPNET Core to NOT
        /// send the SameSite attribute. With ASPNET Core 3.1 the
        ///  enum will have a definition for
        /// Unspecified.

        ///
        private const SameSiteMode Unspecified = (SameSiteMode)(-1);

        ///
        /// Configures a cookie policy to properly set the SameSite attribute
        /// for Browsers that handle unknown values as Strict. Ensure that you
        /// add the
        /// into the pipeline before sending any cookies!

        ///
        ///
        /// Minimum ASPNET Core Version required for this code:
        ///   - 2.1.14
        ///   - 2.2.8
        ///   - 3.0.1
        ///   - 3.1.0-preview1
        /// Starting with version 80 of Chrome (to be released in February 2020)
        /// cookies with NO SameSite attribute are treated as SameSite=Lax.

        /// In order to always get the cookies send they need to be set to
        /// SameSite=None. But since the current standard only defines Lax and
        /// Strict as valid values there are some browsers that treat invalid
        /// values as SameSite=Strict. We therefore need to check the browser
        /// and either send SameSite=None or prevent the sending of SameSite=None.

        /// Relevant links:
        /// - https://tools.ietf.org/html/draft-west-first-party-cookies-07#section-4.1
        /// - https://tools.ietf.org/html/draft-west-cookie-incrementalism-00
        /// - https://www.chromium.org/updates/same-site
        /// - https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/
        /// - https://bugs.webkit.org/show_bug.cgi?id=198181
        ///
        /// The service collection to register  into.

        /// The modified .
        public static IServiceCollection ConfigureNonBreakingSameSiteCookies(this IServiceCollection services)
        {
            services.Configure(options =>
            {
                options.MinimumSameSitePolicy = Unspecified;
                options.OnAppendCookie = cookieContext =>
                   CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
                options.OnDeleteCookie = cookieContext =>
                   CheckSameSite(cookieContext.Context, cookieContext.CookieOptions);
            });

            return services;
        }

        private static void CheckSameSite(HttpContext httpContext, CookieOptions options)
        {
            if (options.SameSite == SameSiteMode.None)
            {
                var userAgent = httpContext.Request.Headers["User-Agent"].ToString();

                if (DisallowsSameSiteNone(userAgent))
                {
                    options.SameSite = Unspecified;
                }
                else
                {
                    options.SameSite = SameSiteMode.Lax;  // 增加这句
                }
            }
        }

        ///
        /// Checks if the UserAgent is known to interpret an unknown value as Strict.

        /// For those the  property should be
        /// set to .
        ///
        ///
        /// This code is taken from Microsoft:
        /// https://devblogs.microsoft.com/aspnet/upcoming-samesite-cookie-changes-in-asp-net-and-asp-net-core/
        ///
        /// The user agent string to check.

        /// Whether the specified user agent (browser) accepts SameSite=None or not.

        private static bool DisallowsSameSiteNone(string userAgent)
        {
            // Cover all iOS based browsers here. This includes:
            //   - Safari on iOS 12 for iPhone, iPod Touch, iPad
            //   - WkWebview on iOS 12 for iPhone, iPod Touch, iPad
            //   - Chrome on iOS 12 for iPhone, iPod Touch, iPad
            // All of which are broken by SameSite=None, because they use the
            // iOS networking stack.

            // Notes from Thinktecture:
            // Regarding https://caniuse.com/#search=samesite iOS versions lower
            // than 12 are not supporting SameSite at all. Starting with version 13
            // unknown values are NOT treated as strict anymore. Therefore we only
            // need to check version 12.

            if (userAgent.Contains("CPU iPhone OS 12")
               || userAgent.Contains("iPad; CPU OS 12"))
            {
                return true;
            }

            // Cover Mac OS X based browsers that use the Mac OS networking stack.

            // This includes:
            //   - Safari on Mac OS X.

            // This does not include:
            //   - Chrome on Mac OS X
            // because they do not use the Mac OS networking stack.

            // Notes from Thinktecture:
            // Regarding https://caniuse.com/#search=samesite MacOS X versions lower
            // than 10.14 are not supporting SameSite at all. Starting with version
            // 10.15 unknown values are NOT treated as strict anymore. Therefore we
            // only need to check version 10.14.

            if (userAgent.Contains("Safari")
               && userAgent.Contains("Macintosh; Intel Mac OS X 10_14")
               && userAgent.Contains("Version/"))
            {
                return true;
            }

            // Cover Chrome 50-69, because some versions are broken by SameSite=None
            // and none in this range require it.

            // Note: this covers some pre-Chromium Edge versions,
            // but pre-Chromium Edge does not require SameSite=None.

            // Notes from Thinktecture:
            // We can not validate this assumption, but we trust Microsofts
            // evaluation. And overall not sending a SameSite value equals to the same
            // behavior as SameSite=None for these old versions anyways.

            if (userAgent.Contains("Chrome/5") || userAgent.Contains("Chrome/6"))
            {
                return true;
            }

            return false;
        }
    }

2、Startup.cs类ConfigureServices方法中添加如下配置

services.ConfigureNonBreakingSameSiteCookies();

参考链接:http://t.zoukankan.com/wjx-blog-p-14803501.html

https://www.thinktecture.com/en/identityserver/prepare-your-identityserver/

Original: https://www.cnblogs.com/sportsky/p/16488992.html
Author: SportSky
Title: identity server4 授权成功页面跳转时遇到错误:Exception: Correlation failed. Unknown location的解决方法

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/609404/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

  • phpcmsv9 后台统计编辑发稿数量

    直切正题: 每个人,每个栏目,发稿数量统计 SELECT a.realname AS 姓名, c.catname AS 栏目名称, count(1) AS 发稿量FROM v9_n…

    Linux 2023年6月13日
    086
  • 玩转 Windows Terminal

    今天给大家分享一下Windows Terminal的使用及个性化定制。 一、安装 该项目的开源地址为https://github.com/microsoft/terminal,如果…

    Linux 2023年6月7日
    0102
  • JDK 环境变量配置

    一、环境准备 Windows10 jdk-9.0.1 二、下载合适的JDK版本,安装JDK 三、环境变量配置 1、右键桌面上”我的电脑”>>&#…

    Linux 2023年6月8日
    080
  • Linux——基础命令用法(下)

    一、linux用户 1、什么是用户 用户用于运行某些进程并拥有某些文件或目录。 [En] Users are used to run certain processes and o…

    Linux 2023年5月27日
    089
  • [Linux] 如何在 Linux 电脑上制作专业的视频教程

    前言 1、软件工具准备 a. 录音软件 b. 录屏软件 c. 摄像头软件 d. 安卓屏幕操作软件 e. 视频剪辑软件 2、视频教程制作 3、效果 参考链接 前言 博主使用 Arch…

    Linux 2023年6月8日
    090
  • LeetCode-16. 最接近的三数之和

    题目来源 题目详情 给你一个长度为 n 的整数数组 nums和 一个目标值 target。请你从 nums 中选出三个整数,使它们的和与 target 最接近。 返回这三个数的和。…

    Linux 2023年6月7日
    093
  • 最新超详细的VMware虚拟机的下载与安装

    一、了解VMware VMware虚拟机软件是一个”虚拟PC”软件,它使你可以在一台机器上同时运行二个或更多Windows、DOS、LINUX系统。与&#8…

    Linux 2023年6月15日
    0120
  • Identity Server 4资源拥有者密码认证控制访问API(二)

    基于上一篇文章中的代码进行继续延伸,只需要小小的改动即可,不明白的地方可以先看看本人上一篇文章及源码: Identity Server 4客户端认证控制访问API 一、 Quick…

    Linux 2023年6月13日
    0103
  • 数据结构-树

    404. 抱歉,您访问的资源不存在。 可能是网址有误,或者对应的内容被删除,或者处于私有状态。 代码改变世界,联系邮箱 contact@cnblogs.com 园子的商业化努力-困…

    Linux 2023年6月11日
    0100
  • RPA 快手自动上传机器人

    bash;gutter:true;1、打开账号Cookie预存表格2、机器人自动登录账号3、机器人开始按照预设视频位置开始自动上传视频4、机器人开始自动填写视频相关信息内容5、完成…

    Linux 2023年6月7日
    0112
  • Redis主从配置总结

    grep ‘^[a-Z]’ /usr/local/redis/conf/redis.conf bind 127.0.0.1 192.168.27.115 protected-mod…

    Linux 2023年5月28日
    085
  • redis订阅关闭异常解决

    redis订阅关闭异常解决 应用程序模块订阅redis运行一段时间出现一直重连Redis服务,日志如下: 2019-04-28 10:06:17,551 ERROR org.spr…

    Linux 2023年5月28日
    0106
  • MySQL架构和存储引擎、系统默认数据库介绍

    采用C/S架构,即客户端/服务器。客户端和服务器区分开,通过客户端发送请求来和服务器交互。 存储引擎:MySQL管理数据文件的一种技术。 myisam innodb myisam特…

    Linux 2023年6月7日
    095
  • ELK-企业级日志分析系统

    ELK 企业级日志分析系统 1.常见日志处理方式 rsyslog: Ryslog是一个强大而安全的日志处理系统。Rsylog通过多个物理或虚拟服务器在网络上接收日志,并监视不同服务…

    Linux 2023年6月13日
    079
  • 七种方案!探讨Redis分布式锁的正确使用姿势

    日常开发中,秒杀下单、抢红包等等业务场景,都需要用到分布式锁。而Redis非常适合作为分布式锁使用。本文将分七个方案展开,跟大家探讨Redis分布式锁的正确使用方式。如果有不正确的…

    Linux 2023年5月28日
    084
  • qsort的cmp函数理解

    近期频繁使用qsort函数,但是对于cmp函数却一直不太熟悉,现用现查。故写一篇小笔记记录一下。 函数原型: void qsort(void *base,size_t NumEle…

    Linux 2023年6月8日
    060
亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球