Reputation: 157
In my ASP.Net Core 3.1 project (Visual Studio 2019), I created an Areas folder and added an Area called "Admin". Within Admin, I added a static folder called "assets". This contains all my CSS, JS, image files for the Admin Area:
In the startup.cs file, I added the following code so I can link to the static files in the assets folder:
I took that code from here: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/static-files?view=aspnetcore-3.1#serve-files-outside-of-web-root
An example link in a view looks like this:
When I run the project locally and browse to /admin, all the assets (CSS, JS, images etc.) are loading and the site is displaying correctly.
However, when I publish my project to azurewebsites.net, the assets are not loading when I browse to /admin! The views are rendered but the CSS, JS and images links are not working.
I have checked the server and the assets folder and files are on the server.
Any help or suggestions for how can make this work on Azure would be much appreciated!
Edit:
When I open web development tools (F12) on the page, the links appears as a 404 error:
"/assets/css/icons.min.css" doesn't exist but why isn't it pointing to /Areas/Admin/assets/css like it does when I run locally?
Edit:
Checking on Azure, it seems as if only the .json files (and folders that have .json files in them) are being published! I linked directly to one of the .json files and it browsed correctly so I need to figure out why VS isn't publishing all the files.
Upvotes: 1
Views: 2290
Reputation: 813
Path.Combine(env.ContentRootPath, "Areas/Admin/assets")),RequestPath = "/assets"
Checking on Azure, it seems as if only the .json files (and folders that have .json files in them) are being published! I linked directly to one of the .json files and it browsed correctly so I need to figure out why VS isn't publishing all the files.
Upvotes: 1