CorrelationId icon indicating copy to clipboard operation
CorrelationId copied to clipboard

Examples don't seem to work for .net 6 mvc web app

Open sarchibald-mdsol opened this issue 2 years ago • 1 comments

I've created a new .net6 mvc web app using vs2022 & the standard project template. When I add via nuget the CorrelationId package, and modify program.cs and then run, my first page load shows:

The 'X-Correlation-ID' request header is required, but was not found.

Here's my code ...

           builder.Services.AddDefaultCorrelationId(options =>
            {
                options.CorrelationIdGenerator = () => Guid.NewGuid().ToString();
                options.AddToLoggingScope = true;
                options.EnforceHeader = true;
                options.IgnoreRequestHeader = false;
                options.IncludeInResponse = true;
                options.RequestHeader = "My-Custom-Correlation-Id";
                options.ResponseHeader = "X-Correlation-Id";
                options.UpdateTraceIdentifier = false;
            });
            var app = builder.Build();
            // Configure the HTTP request pipeline.
            if (app.Environment.IsDevelopment())
            {
                app.UseMigrationsEndPoint();
            }
            else
            {
                app.UseExceptionHandler("/Home/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.UseCorrelationId();
            app.UseRouting();
            app.UseAuthentication();
            app.UseAuthorization();

sarchibald-mdsol avatar Feb 26 '23 22:02 sarchibald-mdsol

@sarchibald-mdsol Are you including a header My-Custom-Correlation-Id in your request? With EnforceHeader=true, this is the expected behaviour if incoming requests do not include the header. I cannot reproduce an issue when the expected header is present.

stevejgordon avatar Feb 27 '23 07:02 stevejgordon