I want to serve .apk
files in my ASP.NET Core MVC project, and I can't since it returns 404.
I created a simple ASP.NET Core MVC project using default template in VS 2017, and added the .apk
file to wwwroot
folder, and then I tried to reach it using /application.apk
path, and it didn't work, while /favicon.ico
works, and other static contents in that directory work, because in default template app.UseStaticFiles()
is called.
I then tried to change configurations, brought static contents out of wwwroot
folder and put the application.apk
in the root directory of the project (one folder up from wwwroot
) and configured the project using:
app.UseStaticFiles(new StaticFileOptions()
{
FileProvider = new PhysicalFileProvider(Directory.GetCurrentDirectory())
});
Again no result. I get 404.
Then I created a Web.config
file and added this MIME Type:
<staticContent>
<mimeMap fileExtension=".apk" mimeType="application/vnd.android.package-archive" />
</staticContent>
Still, doesn't serve the .apk
file.
What should I do?
The ASP.NET Core Static files middleware apparently doesn't serve files which don't have a mapping to a MIME type in the ContentTypeProvider
. To solve this, you should add the MIME mapping to the ContentTypeProvider
:
FileExtensionContentTypeProvider contentTypes = new FileExtensionContentTypeProvider();
contentTypes.Mappings[".apk"] = "application/vnd.android.package-archive";
app.UseStaticFiles(new StaticFileOptions
{
ContentTypeProvider = contentTypes
});
Now the .apk
will be served.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With