C# 异常:尝试登录Microsoft时关联失败

C# 异常:尝试登录Microsoft时关联失败,c#,asp.net-core,asp.net-identity,blazor,blazor-server-side,C#,Asp.net Core,Asp.net Identity,Blazor,Blazor Server Side,在遵循有关如何添加Microsoft帐户登录的文档后,我得到以下异常。关于这个问题还有很多其他问题,但没有一个解决方案对我有效 我使用默认的身份实现(项目创建时的个人用户帐户) Startup.cs: public void ConfigureServices(IServiceCollection services) { services.AddBlazorise(options => { options.ChangeTex

在遵循有关如何添加Microsoft帐户登录的文档后,我得到以下异常。关于这个问题还有很多其他问题,但没有一个解决方案对我有效

我使用默认的身份实现(项目创建时的个人用户帐户)

Startup.cs:

public void ConfigureServices(IServiceCollection services)
    {
        services.AddBlazorise(options =>
        {
            options.ChangeTextOnKeyPress = true; // optional
        })
        .AddBootstrapProviders()
        .AddFontAwesomeIcons();

        services.AddDbContext<UserDbContext>(options =>
            options.UseSqlServer(
                Configuration.GetConnectionString("ASPIdentityDB")));

        services.AddDefaultIdentity<ApplicationUser>(options => options.SignIn.RequireConfirmedAccount = true)
            .AddEntityFrameworkStores<UserDbContext>();

        services.AddAuthentication().AddMicrosoftAccount(options =>
        {
            options.ClientId = Configuration["Authentication:Microsoft:ClientId"];
            options.ClientSecret = Configuration["Authentication:Microsoft:ClientSecret"];
        });

        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddScoped<AuthenticationStateProvider, RevalidatingIdentityAuthenticationStateProvider<ApplicationUser>>();
        services.AddDatabaseDeveloperPageExceptionFilter();

        services.AddSingleton<WeatherForecastService>();

        services.AddResponseCompression(opts =>
        {
            opts.MimeTypes = ResponseCompressionDefaults.MimeTypes.Concat(
                new[] { "application/octet-stream" });
        });

        services.AddSingleton<IUserIdProvider, NameUserIdProvider>();
        services.AddSignalR();
    }

    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        app.UseResponseCompression();

        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            app.UseMigrationsEndPoint();
        }
        else
        {
            app.UseExceptionHandler("/Error");
            // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
            app.UseHsts();
        }

        app.UseHttpsRedirection();
        app.UseStaticFiles();

        app.UseRouting();

        app.UseAuthentication();
        app.UseAuthorization();

        app.UseEndpoints(endpoints =>
        {
            endpoints.MapControllers();
            endpoints.MapBlazorHub();
            endpoints.MapFallbackToPage("/_Host");
        });
    }
public void配置服务(IServiceCollection服务)
{
services.AddBlazorise(选项=>
{
options.ChangeTextOnKeyPress=true;//可选
})
.AddBootstrapProviders()
.AddFontAwesomeIcons();
services.AddDbContext(选项=>
options.UseSqlServer(
GetConnectionString(“ASPIdentityDB”);

services.AddDefaultIdentity

在我的案例中,解决方案是添加以下简单的cookie策略:

app.UseCookiePolicy(new CookiePolicyOptions()
            {
                HttpOnly = HttpOnlyPolicy.Always,
                Secure = CookieSecurePolicy.Always,
                MinimumSameSitePolicy = SameSiteMode.None
            });