Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

FileExtensionContentTypeProvider does not include JSON files - reasoning? #444

Open
AlexUrbanAc opened this issue Mar 23, 2022 · 2 comments
Milestone

Comments

@AlexUrbanAc
Copy link

Hello,

while using the StaticFilesMiddleware I noticed that the ".json" extension is not known in the FileExtensionContentTypeProvider, thus JSON files are not delivered if "ServeUnknownFileTypes" is set to false.

Is this a similar oversight like how old versions of IIS (IIRC Windows Server 2008 R2) did not serve .json files by default, while newer versions (IIRC Windows Server 2013) do so, or did you leave that file type out for a good reason?

Kind regards,

Alexander

@Tratcher
Copy link
Member

The list was copied from IIS a long time ago and never updated. We try to avoid adding everything, but json is a reasonable one.

This was added to ASP.NET Core:
https://github.com/dotnet/aspnetcore/blob/4686703ff8ef199580300e8056142abe44311a1b/src/Middleware/StaticFiles/src/FileExtensionContentTypeProvider.cs#L150

Would you like to send a PR?

@CZEMacLeod
Copy link

You could (temporarily at least) either add a passthrough provider including JSON or proxy the ASP.NET Core 2.2 version.
I did a very rough proof of concept for that here.

<:thought_balloon:>
It is a pity, in some respects, that the separate nuget packages targeting netstandard were dropped, or that some of these kinds of facilities weren't kept in a separate package altogether.
I could definitely see scenarios where inferring the content type from a file extension would be useful - a command line or even MAUI (batch) upload to azure blob storage comes immediately to mind.
You can see this kind of issue at https://github.com/dotnet/aspnetcore/blob/main/src/Components/WebView/WebView/src/FileExtensionContentTypeProvider.cs where it even comments of this problem in the source of the class

// NOTE: This file is copied from src/Middleware/StaticFiles/src/IContentTypeProvider.cs
// and made internal with a namespace change.
// It can't be referenced directly from the StaticFiles package because that would cause this package to require
// Microsoft.AspNetCore.App, thus preventing it from being used anywhere ASP.NET Core isn't supported (such as
// various platforms that .NET MAUI runs on, such as Android and iOS).

There is also the duplication of the mediatype/content type strings in the MediaTypeNames class in the System.Net.Mime Namespace.
I have often thought it strange that there isn't a good/comprehensive single 'source of truth' for these constants (preferably in an updatable package) as part of the primary .net ecosystem. By primary I mean directly supported/published by Microsoft (or I guess DNF).
</:thought_balloon:>

@Tratcher Tratcher added this to the Backlog milestone Nov 16, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants