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)

大家都在看

  • SQLI-LABS(Less-9、10)

    Less-9(GET-Blind-Time based-Single Quotes) 打开 Less-9页面,可以看到页面中间有一句 Please input the ID as …

    Linux 2023年6月6日
    0102
  • Redis

    当你的才华不能撑起你的野心时,就是你该选择学习的时候了! Original: https://www.cnblogs.com/hofmann/p/16056013.htmlAuth…

    Linux 2023年5月28日
    087
  • 试吃香甜可口的《程序员面试指南》

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

    Linux 2023年6月6日
    077
  • OpenStack cinder对接NFS后端存储

    配置NFS服务 安装NFS服务 查询是否安装 [root@nfs ~]# rpm -qa |grep nfs nfs-utils-1.3.0-0.8.el7.x86_64 如没有安…

    Linux 2023年6月8日
    0136
  • alloc_pages的实现浅析

    alloc_pages的使用 struct page *alloc_pages(gft_t gfp, unsigned int order) alloc_pages定义于 inux…

    Linux 2023年6月7日
    0107
  • Redis:redis常用操作命令

    redis登录 #登录命令 -h 登录地址 -p 端口 ./redis-cli -h 127.0.0.1 -p 6379 查看缓存大小 #查看缓存大小 dbsize 查看所有Key…

    Linux 2023年5月28日
    0133
  • spring redis session 使用入门[原]

    两份properties配置, 仅端口不同 配置文件添加redis 链接 application-9001.properties application-9002.properti…

    Linux 2023年5月28日
    095
  • Elasticsearch7.X 安装(CentOS7)

    需要Java环境最低1.8起步 Elasticsearch时隔三年出来了8.0版本,最低需要JDK17 一、 获取Elasticsearch7.x安装包 获取链接 Elastics…

    Linux 2023年6月13日
    0112
  • [ Skill ] 如何获取库中的 top cell

    https://www.cnblogs.com/yeungchie/ top cell 的一个特点就是没有被其他的单元所调用,下面举例获取某个库中的 top cell。 1. 获取…

    Linux 2023年6月7日
    0101
  • 深入分析JVM执行引擎

    程序和机器沟通的桥梁 一、闲聊 相信很多朋友在出国旅游,或者与外国友人沟通的过程中,都会遇到语言不通的烦恼。这时候我们就需要掌握对应的外语或者拥有一部翻译机。而笔者只会中文,所以需…

    Linux 2023年6月14日
    0102
  • 06-MyBatis中ResultType和ResultMap的区别

    MyBatis中ResultType和ResultMap的区别 如果数据库结果集中的列名和要封装的属性名完全一致的话用 resultType属性 如果数据库结果集中的列名和要封装实…

    Linux 2023年6月7日
    0103
  • Ubuntu下搭建apache2+GGI环境

    参考:https://blog.csdn.net/nanfeibuyi/article/details/108551159 就先记录步骤吧 Original: https://ww…

    Linux 2023年6月8日
    090
  • SQL55 分页查询employees表,每5行一页,返回第2页的数据

    LIMIT子句 本题链接表结构如下所示。 +——–+————+——&#8…

    Linux 2023年6月13日
    092
  • 微服务架构项目搭建过程中的Mysql安装和相关问题

    搭建微服务架构的过程中需要使用Mysql数据库,Mysql数据库搭建着实不是一个容易的事情,会碰到各种各样的问题,如果没有一个安装数据库的思路真的很难把数据库安装好,并且掉入到安装…

    Linux 2023年6月14日
    0110
  • Ubuntu18.04安装/卸载NVIDIA显卡驱动

    1 显卡驱动下载 官网:NVIDIA 搜索适合本机的驱动 获取最新版本驱动 立即下载 文件 上面,显卡驱动程序下载已完成。 [En] Above, the video card d…

    Linux 2023年5月27日
    0232
  • 如何正确地使用Entity Framework Database First

    毕设依旧在不紧不慢地以每天解决一个问题的进度进行中。今天遇到的问题就是在建立数据模型时遇到的。因为项目是基于数据库构建的,所以理所应当地采用DB First来构造实体类和DbCon…

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