dotnet / dotnet/aspnetcore

[Analyzer] Detect middleware in pipeline after terminal middleware

Open
#44,244 3 comments 3 reactions 0 assignees View on GitHub
analyzer area-middleware area-networking
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 10h
Merged PRs (30d)
281

Description

### Is there an existing issue for this?

- [X] I have searched the existing issues

### Is your feature request related to a problem? Please describe the problem.

Some middleware is terminal. That means it doesn't call the next middleware (if present) and starts the request returning back down the pipeline. For example, `UseSpa` is terminal.

Developers could place middleware after `UseSpa`, not realizing it isn't executed. For example, `UseEndpoints` after `UseSpa`.

This problem also happens with `WebApplication`, which implicitly adds `UseEndpoints` to the end of the pipeline. Any terminal middleware prevents endpoints from being executed.

### Describe the solution you'd like

* Detect middleware after terminal middleware and warn the developer.
* (maybe) Detect terminal middleware with `WebApplication`. Warn the developer they may need to add UseEndpoints before terminal middleware.

### Additional context

_No response_

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.