dotnet/systemweb-adapters

HttpApplicationMiddleware is used even not setting app.UseSystemWebAdapters

Clounea opened this issue · 0 comments

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