dotnet / aspnetcore

ASP.NET Core is a cross-platform .NET framework for building modern cloud-based web applications on Windows, Mac, or Linux.
https://asp.net
MIT License
35.16k stars 9.92k forks source link

Re-Open of issue 2774: UseStaticFiles() will not serve files that are symbolic links #34371

Open fitdev opened 3 years ago

fitdev commented 3 years ago

It's been 3 years since #2774 was closed. However, as of DotNet 6 Preview 6 is still appears not to have been addressed. Since apparently you are adding Symlink support to BCL, can this be addressed perhaps via an option (FollowSymLinks property) in either StaticFileOptions or PhysicalFileProvider?

Additional context

See original issue: https://github.com/dotnet/aspnetcore/issues/2774

davidfowl commented 3 years ago

So 2 things:

Given that, it's unlikely that we'd add it for .NET 6 this late in the cycle. That said, if there was an API proposal and a pull request, that might change things 😄

ghost commented 3 years ago

We've moved this issue to the Backlog milestone. This means that it is not going to be worked on for the coming release. We will reassess the backlog following the current release and consider this item at that time. To learn more about our issue management process and to have better expectation regarding different types of issues you can read our Triage Process.

adityamandaleeka commented 3 years ago

Moved to backlog for now per @davidfowl's explanation.

Tratcher commented 2 years ago

Proposal: https://github.com/dotnet/aspnetcore/issues/5987

davidfowl commented 2 years ago

cc @carlossanlop

lonix1 commented 2 years ago

When I reference a Razor Class Library using a symlink, it compiles without error, though at runtime it doesn't find or serve the library's pages. But if that library is referenced normally (not with a symlink) then it works perfectly.

Is this the same underlying problem? (I didn't want to open a dupe issue.)

fexxdev commented 2 months ago

Issue Description

I'm encountering an issue with Kestrel 8.0.1 (.NET 8.0.1) on macOS where serving static files from symlinks results in incomplete files being served. This problem does not occur on Windows. When you manually copy the files into the destination directory, they are served correctly, indicating the problem lies with how Kestrel handles symlinks on macOS.

Directory Structure and Code

mbp-fexxdev:timesheet fexxdev$ ls -lat
total 0
drwxr-xr-x  14 fexxdev  staff  448 Jun 12 11:28 .
lrwxr-xr-x   1 fexxdev  staff   96 Jun 12 11:15 styles.css.map -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/styles.css.map
lrwxr-xr-x   1 fexxdev  staff   92 Jun 12 11:15 styles.css -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/styles.css
lrwxr-xr-x   1 fexxdev  staff   98 Jun 12 11:15 polyfills.js.map -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/polyfills.js.map
lrwxr-xr-x   1 fexxdev  staff   94 Jun 12 11:15 polyfills.js -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/polyfills.js
lrwxr-xr-x   1 fexxdev  staff   87 Jun 12 11:15 media -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/media
lrwxr-xr-x   1 fexxdev  staff   93 Jun 12 11:15 main.js.map -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/main.js.map
lrwxr-xr-x   1 fexxdev  staff   89 Jun 12 11:15 main.js -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/main.js
lrwxr-xr-x   1 fexxdev  staff   92 Jun 12 11:15 index.html -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/index.html
lrwxr-xr-x   1 fexxdev  staff   93 Jun 12 11:15 favicon.ico -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/favicon.ico
lrwxr-xr-x   1 fexxdev  staff  103 Jun 12 11:15 chunk-XSKKLE2R.js.map -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/chunk-XSKKLE2R.js.map
lrwxr-xr-x   1 fexxdev  staff   99 Jun 12 11:15 chunk-XSKKLE2R.js -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/chunk-XSKKLE2R.js
lrwxr-xr-x   1 fexxdev  staff   88 Jun 12 11:15 assets -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/assets
drwxr-xr-x@  4 fexxdev  staff  128 Jun 12 11:09 ..
mbp-fexxdev:timesheet fexxdev$

ASP.NET Core Startup Configuration:

if (Directory.Exists(ElsaServerOptions.StaticFilesLocation()))
{
    app.UseStaticFiles(new StaticFileOptions()
    {
        FileProvider = new PhysicalFileProvider(ElsaServerOptions.StaticFilesLocation()),
        RequestPath = "/static"
    });
}

Screenshots:

Incomplete index.html when server from symlink

Screenshot 2024-06-12 at 11 28 46

index.html correctly served after manual copy

drwxr-xr-x@  4 fexxdev  staff  128 Jun 12 11:09 ..
mbp-fexxdev:timesheet fexxdev$ cp index.html index2.html
mbp-fexxdev:timesheet fexxdev$ ls -lat
total 8
-rw-r--r--   1 fexxdev  staff  602 Jun 12 11:29 index2.html
drwxr-xr-x  15 fexxdev  staff  480 Jun 12 11:29 .
lrwxr-xr-x   1 fexxdev  staff   96 Jun 12 11:15 styles.css.map -> /Users/fexxdev/Desktop/Dev/Nebula/jarvis.automation.components/src/timesheet/dist/styles.css.map
lrwxr-xr-x   1 fexxdev  staff   92 Jun 12 11:15 sty....

Screenshot 2024-06-12 at 11 29 48 (don't mind the fact that the page is blank, it is expected. But the content is there as you can see)

Any thoughts? Thanks!

Tratcher commented 2 months ago

@fexxdev 2.2.0 is way out of support, you need to be on .NET 6 or 8 these days.

fexxdev commented 2 months ago

@Tratcher i'm sorry for the confusion, i though one thing and wrote another 😅 I'm using .NET 8.0.1