IdentityServer4采用Http时在谷歌最新浏览器登录后不跳转

startup类添加代码:

 

public void SetSameSite(HttpContext httpContext, CookieOptions options)
    {
        if (options.SameSite == SameSiteMode.None)
        {
            if (httpContext.Request.Scheme != "https")
            {
                options.SameSite = SameSiteMode.Unspecified;
            }
        }
    }
    public override void ConfigureServices(ServiceConfigurationContext context)
    {
        var hostingEnvironment = context.Services.GetHostingEnvironment();
        var configuration = context.Services.GetConfiguration();
        Configure<CookiePolicyOptions>(options =>
        {
            options.MinimumSameSitePolicy = SameSiteMode.Unspecified;
            options.OnAppendCookie = cookieContext =>
                SetSameSite(cookieContext.Context, cookieContext.CookieOptions);
            options.OnDeleteCookie = cookieContext =>
                SetSameSite(cookieContext.Context, cookieContext.CookieOptions);
        });
 }

public override void OnApplicationInitialization(ApplicationInitializationContext context)
    {
        var app = context.GetApplicationBuilder();
        var env = context.GetEnvironment();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
        }

        app.UseAbpRequestLocalization();

        if (!env.IsDevelopment())
        {
            app.UseErrorPage();
        }
        app.UseCookiePolicy();
        app.UseCorrelationId();

} 

 

posted @ 2022-07-14 18:45  沐雪架构师  阅读(77)  评论(0编辑  收藏  举报