How to fix HTTP Error 404 when download static file in ASP.NET core?

You may get an HTTP Error 404 when browsing/downloading a static file like .Apk when the client should be downloaded after publishing asp.net core application to the host. This means there is no matched MIME type for the target file extension in the FileExtensionContentTypeProvider to process the request. You can add the specific MIME type from your application Program.cs file to sort out the problem.
 
using Microsoft.AspNetCore.StaticFiles;

var builder = WebApplication.CreateBuilder(args);

...

var app = builder.Build();

...

app.UseStaticFiles();

app.UseStaticFiles(new StaticFileOptions
{
    ContentTypeProvider = new FileExtensionContentTypeProvider(new Dictionary<string, string>
    {
        {".apk", "application/vnd.android.package-archive"},
        {".nupkg", "application/zip"}
    })
});

...

app.Run();
 
  • ASP.NET, Asp.Net core, 404 error, static file, asp.net core, HTTP Error 404, .Apk
  • 0 Users Found This Useful
Was this answer helpful?

Related Articles

How to publish ASP.NET Core from visual studio 2022 as Self-Contained?

Here is instruction how to publish ASP.NET core with self contained (i.e. where all the...

How to turn off dotnet app by using the App Offline file app_offline.htm?

However,  dotnet application is loading .dll/.exe files in an individual process to run the...

how to create simple webscoket in ASP.NET with SignalR?

1.) Create "ASP.NET Core Web App (C#)" in Visual Studio 2.) Add the SignalR client library In...

How to Use IdentityServer in ASP.NET Core with Certificate Signing?

Creating and Adding the Certificate To create and add a certificate to your machine's...

Powered by WHMCompleteSolution