Custom Javascript/Css files are returning 404 resource not found when deploying .net 8 Razor Pages web app. The page loads Site.js/.css perfectly fine and all the files are in respective directories what could the issue be?

Nunez, Juan 0 Reputation points
2024-11-20T18:22:14.6+00:00

So I developed a simple .net 8 razor pages tool that uses two custom.js files that work fine locally but when I deploy to server in IIS they return 404 resource not found. The site.js/.css files load perfectly fine and all the files are located in the appropriate directories on the server. What could be causing this issue? I am using app.UseStaticFiles() which should serve the all the static files from the wwroot. I have tried adding builder.UseStaticWebAssests() as well and still get the same thing. I have checked the permissions to the files on the server and as far as I can see the permissions are the same for the site.js and my custom.js files. Anyone have a clue as to what else can be checked?

ASP.NET
ASP.NET
A set of technologies in the .NET Framework for building web applications and XML web services.
3,539 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Bruce (SqlWork.com) 68,236 Reputation points
    2024-11-26T16:53:48.32+00:00

    if site.js is working, than static files are being returned. use the browsers network tool to verify the path used to access the files.

    note: builder.UseStaticWebAssests() is used to support static files that are part of a Razor Class Library. Basically stored as a resource instead of a file.


Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.