【问题标题】:How to resolve Request to Long error in Asp.Net Core Azure B2C Configuraiton?如何解决 Asp.Net Core Azure B2C 配置中的 Request too Long 错误?
【发布时间】:2021-03-27 17:44:03
【问题描述】:

我是 Asp.Net Core 身份的新手。

我已按照以下配置启动。当我在普通的隐身浏览器中运行代码时,出现以下错误。

我已按照之前问题的建议清除了 cookie。有趣的是在加载标志屏幕时会创建大量 cookie。

我的问题类似于以下旧文章中描述的问题。这两种解决方案似乎都过时了。

using d365fl.DocumentGenerator.blazor_frontend.Data;
using Microsoft.AspNetCore.Authentication.OpenIdConnect;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Components;
using Microsoft.AspNetCore.Hosting;
using Microsoft.AspNetCore.HttpsPolicy;
using Microsoft.AspNetCore.Mvc.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Hosting;
using Microsoft.Identity.Web;
using Microsoft.IdentityModel.Logging;

namespace d365fl.DocumentGenerator.blazor_frontend
{
public class Startup
{
    public Startup(IConfiguration configuration)
    {
        Configuration = configuration;
    }

    public IConfiguration Configuration { get; }

    // This method gets called by the runtime. Use this method to add services to the container.
    // For more information on how to configure your application, visit https://go.microsoft.com/fwlink/?LinkID=398940
    public void ConfigureServices(IServiceCollection services)
    {

        ConfigureIdentiy(services);

        services.AddRazorPages();
        services.AddServerSideBlazor();
        services.AddSingleton<WeatherForecastService>();
    }

    private void ConfigureIdentiy(IServiceCollection services)
    {
        services.AddMicrosoftIdentityWebAppAuthentication(Configuration, "AzureAdB2C");

        services.AddControllersWithViews(options =>
        {
            var policy = new AuthorizationPolicyBuilder()
                .RequireAuthenticatedUser()
                .Build();
            options.Filters.Add(new AuthorizeFilter(policy));
        });

        services.Configure<OpenIdConnectOptions>(Configuration.GetSection("AzureAdB2C"));
    }
    // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
    public void Configure(IApplicationBuilder app, IWebHostEnvironment env)
    {
        if (env.IsDevelopment())
        {
            app.UseDeveloperExceptionPage();
            IdentityModelEventSource.ShowPII = true;
        }
        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");
        });
    }
}

}

编辑 1 - 来自开发者工具栏的 HTTP 请求

EDIT 2 - 来自开发者工具栏/网络选项卡的 Cookie 数据的屏幕截图

【问题讨论】:

  • 可能是cookies太多造成的。见stackoverflow.com/questions/46100272/…
  • 这正是问题所在。但是,cookie 是由于某种类型的无限循环/从应用程序到登录屏幕来回的多次请求而生成的。对不起,糟糕的术语 AD Auth 对我来说是新的。

标签: asp.net-core asp.net-identity azure-ad-b2c


【解决方案1】:

正如我们在评论中所讨论的,问题是由太多 cookie 引起的。

请清除您的 cookie 并修改您的代码以避免无限循环和来回请求。

查看answer了解更多详情。

【讨论】:

  • 我已经清除了cookies。我已尝试根据上述文章减少索赔数量。我还尝试了不同的浏览器和私有模式下的不同浏览器。不幸的是,这并没有解决问题。 :(
  • @user3845056 能不能用抓包工具抓取请求来查看header有多长?
  • 请参阅上方的编辑“编辑 1 - 来自开发人员工具栏的 HTTP 请求”,它有一个屏幕截图显示请求是 442b,看起来并不大。我捕捉到了正确的东西吗?
  • @user3845056 不确定。内容分享方便吗?
  • 请参阅编辑 2 - 来自开发人员工具栏/网络选项卡的 Cookie 数据的屏幕截图。一个 cookie 的数据量非常大。
猜你喜欢
  • 2016-01-25
  • 1970-01-01
  • 2020-07-31
  • 2018-12-23
  • 1970-01-01
  • 2012-01-27
  • 2015-03-17
  • 2021-12-14
  • 2018-02-06
相关资源
最近更新 更多