MapStaticAssets should support more powerful routing
- Dominant language
- C#
- Stars
- 38.4k
- Forks
- 10.9k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 290
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.
There's no straightforward way to configure routing for different parts of static assets.
For example to allow anonymous access to some static files and require auth for others.
- `/path1/...` -> allow anonymous
- `/path2/...` -> require auth
There are solutions using different approaches like middleware that branch the pipeline, or manually handling requests. These are hard to reason about and don't interact well with features like `.MapFallbackToFile(...)`. We also can't take advantage of the optimizations available to `MapStaticFiles` using these workarounds.
### Describe the solution you'd like
I'd like to be able to apply a path prefix and filter to the endpoints generated by `MapStaticAssets()`.
```csharp
app.MapStaticAssets("/path1").AllowAnonymous();
app.MapStaticAssets("/path2").RequireAuthorization();
```
There are even "samples" of this functionality on the internet that appear to be LLM generated 😉
### Additional context
_No response_
Contributor guide
Assessment
This issue has not been assessed yet.