Skip to content

IExceptionHandlerFeature is not available in CustomizeProblemDetails when using UseDeveloperExceptionPage #47060

@bjornen77

Description

@bjornen77

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The IExceptionHandlerFeature is not available in CustomizeProblemDetails when using "UseDeveloperExceptionPage". It is, however, available when using "UseExceptionHandler()". Is there a reason for this? It would be good to be able to customize the problem details also when using the DeveloperExceptionPage.

Expected Behavior

The IExceptionHandlerFeature is available when using DeveloperExceptionPage

Steps To Reproduce

Try the "/" endpoint from swagger.

using Microsoft.AspNetCore.Diagnostics;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();

builder.Services.AddProblemDetails(configure =>
    configure.CustomizeProblemDetails = (context) =>
    {
        if (context.HttpContext.Features.Get<IExceptionHandlerFeature>() is IExceptionHandlerFeature exceptionHandlerFeature)
        {
            Console.WriteLine("This will not print when using UseDeveloperExceptionPage()");
        }
    }
);

var app = builder.Build();

app.UseDeveloperExceptionPage();

app.UseSwagger();
app.UseSwaggerUI();

app.MapGet("/", () =>
{
    throw new Exception();
});

app.Run();

Exceptions (if any)

No response

.NET Version

7.0.201

Anything else?

No response

Metadata

Metadata

Assignees

Labels

area-middlewareIncludes: URL rewrite, redirect, response cache/compression, session, and other general middlewareshelp wantedUp for grabs. We would accept a PR to help resolve this issue

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions