In .net core how to download a static file with special extension in web root?

After reading this article and this one can not handle Serve files in web root (.net core 3.1).

There is a CB folder in the webroot folder and I can browse any txt or png file it works fine but when I want to download an apk file it doesn’t work and browser message files not found.

this is my folders structure:

-wwwroot
   -CB
     myfile.apk

installed “Microsoft.AspNetCore.StaticFiles” and used:

 app.UseStaticFiles();

tested URL:

http://localhost:51405/cb/myfile.apk

Answers:

Thank you for visiting the Q&A section on Magenaut. Please note that all the answers may not help you solve the issue immediately. So please treat them as advisements. If you found the post helpful (or not), leave a comment & I’ll get back to you as soon as possible.

Method 1

From the second article, it explicity states to configure UseStaticFiles() options via its parameter and specify that static files should be served even if the file type is unknown.

app.UseStaticFiles(new StaticFileOptions
    {
        ServeUnknownFileTypes = true
    });

Like the article states, however, this is a pretty big security risk. Proceed with caution.


All methods was sourced from stackoverflow.com or stackexchange.com, is licensed under cc by-sa 2.5, cc by-sa 3.0 and cc by-sa 4.0

0 0 votes
Article Rating
Subscribe
Notify of
guest

0 Comments
Oldest
Newest Most Voted
Inline Feedbacks
View all comments
0
Would love your thoughts, please comment.x
()
x