0

Recently, ASP.NET Core 9 released a new middleware, app.MapStaticAssets();, to enhance the delivery of static resources.

I’ve been deploying an ASP.NET Core MVC project on a Linux virtual machine, and everything works as expected, except for the static files (CSS, JS, images, etc.). However, using app.UseStaticFiles(); works perfectly.

Can anyone help me identify what I might be missing or misconfigured?

For your reference, here’s a snippet from my Nginx config file for serving static files:

    # MIME type handling for static files
      location ~* ^.+\.(css|js|jpg|jpeg|gif|png|ico|gz|svg|svgz|ttf|otf|woff|woff2|eot|mp4|ogg|ogv|webm|webp|zip|swf|map)$ {
        root /path/to/my/app/wwwroot;
        add_header Access-Control-Allow-Origin "*";
        expires max;
        access_log off;
      }```
6
  • Can you access the static files directly? Also try clearing the browser cache as this sometimes causes issues. Commented Jan 25 at 17:06
  • Yes I tried both of them. But didn't works Commented Jan 25 at 18:19
  • I do not think it is about static files. I think it is about binary files. What is the content type you are specifying in the MIME header? Commented Jan 25 at 20:33
  • text/html. I am trying to deploy a default MVC application. So everything is kept as default Commented Jan 26 at 6:52
  • Hi @a_n_rajin, I have test it in my ubuntu server, it works well. Could you find the wwwroot folder inside publish files? And I recommend you can enable asp.net core logging to check what happened. Commented Jan 27 at 12:59

1 Answer 1

0

For some reason, if you disable hot reload in the launchSettings.json, it works:

"https": {
  "commandName": "Project",
  "dotnetRunMessages": true,
  "launchBrowser": true,
  "applicationUrl": "https://localhost:5131;http://localhost:5130",
  "hotReloadEnabled": false,
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  }
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.