UseStaticFiles for HTML
I have generated a Static WebApp from my Markdown Files.
I want this to serve the File "Documentation/Userguide.html" if the route is "/docs/Userguide"
If i serve it via NGNIX i would configure something like this
14 Replies
Now im looking for something equivalent in asp.net core
the first thing I came up with is a simple middleware:
But i don't like it
How does that process the
.html
suffix?It just serves all the files wholesale, as they are
You request
/docs/index.html
it serves index.html
from docs
directory
You request /docs/skunga.xyz
you get skunga.xyz
Just like wwwroot
The question is specifically about how to serve the file
Foo.html
from the route /docs/Foo
OP already has the code you posted in their question. They're asking something elseAh, damn, you're right
In that case I'd either stick to this custom middleware, or I'd write a controller that does that
It doesn't look like there's anything in
PhysicalFileProvider
to support this
Something like this should work
Be very VERY careful there.
PhysicalFileProvider
has a lot of stuff to prevent you from traversing outside of the webroot. Your code has none of that
I suspect I could read any file on the filesystem with thatHuh, would
File.Open()
accept a path like docs/../../../../../../../../secretpasswords.html
?Sure
How do you overcome wanting a
.pubkey
file with the .html
extension being hardcoded into the path?https://source.dot.net/#Microsoft.Extensions.FileProviders.Physical/PhysicalFileProvider.cs,c7243b62fd6ea79f, look for
PathUtils.PathNavigatesAboveRoot
and IsUnderneathRoot
Thanks for your help @ZZZZZZZZZZZZZZZZZZZZZZZZZ & @canton7.
That try_files feature would be useful in UseStaticFiles because it seems that many SSGs rely on that behavior.
Ill stick with the Middleware for now. It works & there are no conflicts (at least for my static files)