dotnet / dotnet/aspnetcore

When using UseStaticFiles, AspNetCore does not call CreateReadStream to get a stream to return via http but rather uses the PhysicalPath to create it's own stream.

Open
#53,425 4 comments 0 reactions 0 assignees View on GitHub
area-networking Docs Needs: Attention :wave:
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

### Describe the bug

ASPNetCore ignoring the stream i am exposing in IFileInfo when SendFileRepsonseExtensions.SendFileAsyncCore(HttpResponse, IFileInfo...) is used and using the PhysicalPath.

at Microsoft.AspNetCore.Http.SendFileFallback.SendFileAsync(Stream destination, **String filePath**, Int64 offset, Nullable`1 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.SendFileResponseExtensions.SendFileAsyncCore(HttpResponse response, **String fileName**, Int64 offset, Nullable`1 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.Http.SendFileResponseExtensions.SendFileAsyncCore(HttpResponse response, **IFileInfo file**, Int64 offset, Nullable`1 count, CancellationToken cancellationToken)
at Microsoft.AspNetCore.StaticFiles.StaticFileContext.SendAsync()
at Microsoft.AspNetCore.StaticFiles.StaticFileContext.ServeStaticFile(HttpContext context, RequestDelegate next)

### Expected Behavior

If use provide my own IFileProvider in the options for UseStaticFiles, I expect ASPNETCore to return the stream that i am exposing and not create it's own using the PhysicalPath.

### Steps To Reproduce

_No response_

### Exceptions (if any)

_No response_

### .NET Version

8.0.101

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