Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Some vendors mandate the hosting of extension-less static files for the use of their services, such as Apple with their .well-known/apple-developer-merchantid-domain-association or .well-known/apple-app-site-association files.
As far as I know, this is currently doable with .net only by enabling the ServeUnknownFileTypes option from StaticFileOptions, which is a lot "wider" than the need and is a bigger security risk than enabling an extension-less file mapping.
Describe the solution you'd like
The FileExtensionContentTypeProvider alreayd accepts en empty extension mapping, like this:
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[""] = "text/plain";
But its implementation short-circuit on extension-less path, causing the declaration to be useless.
Its GetExtension method yields null in such case, which causes the middleware to not try to lookup its extension table.
|
int index = path.LastIndexOf('.'); |
|
if (index < 0) |
|
{ |
|
return null; |
|
} |
If it were to yield the empty string in such case instead, it should allow to map extension-less files.
Additional context
Currently we use this workaround:
app.UseStaticFiles(
new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", ".well-known")),
RequestPath = "/.well-known",
ServeUnknownFileTypes = true,
DefaultContentType = "text/plain"
});
We would rather use:
var provider = new FileExtensionContentTypeProvider();
provider.Mappings[""] = "text/plain";
app.UseStaticFiles(
new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot", ".well-known")),
RequestPath = "/.well-known",
ContentTypeProvider = provider
});
By the way, that is still not "good" as we wish. When served through IIS static file handler, we restrict it further to only the file path. But that does not seem doable with the .net API as currently is.
Example through IIS:
<location path=".well-known/apple-developer-merchantid-domain-association">
<system.webServer>
<staticContent>
<mimeMap fileExtension="." mimeType="text/plain" />
</system.webServer>
</location>
And in case we needed to host an .well-known/apple-app-site-association file too, we would be stuck not being able to specify two different mime types for these two extension-less files.
Is there an existing issue for this?
Is your feature request related to a problem? Please describe the problem.
Some vendors mandate the hosting of extension-less static files for the use of their services, such as Apple with their
.well-known/apple-developer-merchantid-domain-associationor.well-known/apple-app-site-associationfiles.As far as I know, this is currently doable with .net only by enabling the
ServeUnknownFileTypesoption fromStaticFileOptions, which is a lot "wider" than the need and is a bigger security risk than enabling an extension-less file mapping.Describe the solution you'd like
The
FileExtensionContentTypeProvideralreayd accepts en empty extension mapping, like this:But its implementation short-circuit on extension-less path, causing the declaration to be useless.
Its GetExtension method yields null in such case, which causes the middleware to not try to lookup its extension table.
aspnetcore/src/Middleware/StaticFiles/src/FileExtensionContentTypeProvider.cs
Lines 455 to 459 in 8a68740
If it were to yield the empty string in such case instead, it should allow to map extension-less files.
Additional context
Currently we use this workaround:
We would rather use:
By the way, that is still not "good" as we wish. When served through IIS static file handler, we restrict it further to only the file path. But that does not seem doable with the .net API as currently is.
Example through IIS:
And in case we needed to host an
.well-known/apple-app-site-associationfile too, we would be stuck not being able to specify two different mime types for these two extension-less files.