dotnet / dotnet/aspnetcore

MapStaticAssets causes HTTP error 405 on POSTs with UseWhen

Open
#65,940 2 comments 0 reactions 0 assignees View on GitHub
Needs: Attention :wave:
Dominant language
C#
Stars
38.4k
Forks
10.9k
Avg merge
2d 5h
Merged PRs (30d)
276

Description

### Is there an existing issue for this?

- [x] I have searched the existing issues

### Describe the bug

I'm using "MapStaticAssets()" to serve static files. Further down in the request pipeline, I'm using "UseWhen(...)" to conditionally call a middleware for POST requests.
However, POST requests do not reach my middleware and instead return HTTP error 405 "Method not allowed" as long as "MapStaticAssets()" is part of the pipeline.

### Expected Behavior

POST requests should be handled by my conditional middleware and not return HTTP error 405

### Steps To Reproduce

Minimal project to reproduce the problem: https://github.com/ecosFWinkel/Bug_MapStaticAssets405

Run the project and issue a POST request:
```
curl "http://localhost:5065" -d "Hello world" -f
```

This will cause a 405 error. You won't get this error when commenting "endpoints.MapStaticAssets()" in line 12

### Exceptions (if any)

_No response_

### .NET Version

10.0.201

### Anything else?

_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.