Skip to content

HttpApplicationMiddleware is used even not setting app.UseSystemWebAdapters #405

@Clounea

Description

@Clounea

Describe the bug

We have a health check API which we don't want the request go through the httpmodules. The code we use is like below. But the service log shows that health check API still uses httpmodules.

builder.Services.AddSystemWebAdapters()
.WrapAspNetCoreSession()
.AddHttpApplication<MyHttpApplication>(
(options) =>
{
    options.RegisterModule<MyRequestModule>("MyRequestModule");
});
builder.Services.AddControllers();

WebApplication app = builder.Build();

app.UseRouting();

 app.MapWhen(context=>context.Request.Path.StartsWithSegments("/health"), appBuilder =>
 {
   appBuilder.UseEndpoints(endpoints =>
   {
     endpoints.MapHealthChecks("/health");
   });
 });
 
app.UseAuthenticationEvents();
app.UseAuthorizationEvents();
app.UseSystemWebAdapters();
endpoints.MapControllers();

To Reproduce

Set breakpoint in the MyRequestModule.
Use the code above to configure the application. And request /health.
Then the breakpoint will be hit.

Further technical details

In this change, HttpApplicationMiddleware is moved to IStartUpFilter. So even I don't set "UseSystemWebAdapters" for health check API, the middleware still run and httpmodules still work.
The stacktrace is as below.

image

Metadata

Metadata

Assignees

No one assigned

    Labels

    In-PRIssues that have a PR open for them.Needs: Triage 🔍Label added to new issues which need Triage

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions