Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Daniel 4 posts 85 karma points
    Apr 30, 2024 @ 00:42
    Daniel
    0

    Fresh Umbraco build 404'ing static files

    Hey! I recently booted up a fresh Umbraco build (v13.3.0) and tried porting in some files to new directories but I noticed that the files were all running into a 404 error. Paths are definitely correct - and I can access the same files IF they're imported via the CMS. For example, none of these were accessible:

    /example.min.js
    /js/example.min.js
    /scripts/example.min.js
    /scripts/test/example.min.js
    

    I also tried the same thing with a CSS file and a PNG image, all of which 404'd as well.

    However, if I create a new script in the CMS with the same path, same filename etc. that routes correctly and displays the raw content of the file as expected. Same with using the App_Plugins directory - if I chuck the same files into there, they route fine with no issues.

    For some added context, I'm using Visual Studio 2022 (free version) and installed Umbraco using the .NET templates as instructed on the docs guide (dotnet new install Umbraco.Templates). Umbraco itself, and the site etc all works absolutely fine - it's just accessing static files outside the context of Umbraco that seems to be the problem.

    I figure it's most likely something to do with how I've set it up, and I've tried googling around and searching the forums in case anyone's run into the same issue, but didn't have much luck there. Hoping someone else has run into this before, or has some advice to pass on.

    I thought maybe it might come down to adding in some custom routing code with a content finder but I'm still unsure as to whether or not this is expected behavior since the last version of Umbraco I used was much older (Pre-Core) but didn't have this issue.

    Let me know if there's any useful bits of info I can provide that I've missed out above.

    Any help or advice is greatly appreciated! :)

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    Apr 30, 2024 @ 10:31
    Nik
    0

    Hi Daniel,

    Where exactly did you put the static assets on the file system? Could you share a screen shot?

    Thanks

    Nik

  • Daniel 4 posts 85 karma points
    Apr 30, 2024 @ 23:01
    Daniel
    0

    Hi Nik,

    Sure! No problem - I tried a number of places, but the idea is just to have something like a "/assets/js/globals.js" type of set up going. Also, being able to link to things like PDFs etc. that live outside the uploaded "/media" folder (eg. /documents/something.pdf). I've attached a couple of screenshots which show the file locations as they exist in the filesystem and also the 404 when attempting to access those same locations. If there's anything else helpful I can provide just let me know.

    Many thanks!

    file system screenshot

    404 on attempted access

  • Nik 1614 posts 7260 karma points MVP 7x c-trib
    May 01, 2024 @ 08:03
    Nik
    100

    Hi Daniel,

    In .Net Core / Umbraco 9+ you need to put your static assets in the wwwroot folder, not at the root of the project. The wwwroot folder is what is served up as the web root "/" by default now when it comes to those sorts of things. Even the App_Plugins folder, when deployed would actually be served from within the wwwroot folder.

    This was a .Net Core change around web applications which Umbraco had to follow along with.

    Thanks

    Nik

  • Daniel 4 posts 85 karma points
    May 01, 2024 @ 23:31
    Daniel
    1

    Hi Nik,

    Ahh! Brilliant! Sorry, I hadn't even noticed the wwwroot folder was where the Umbraco created scripts were being stored since URL-wise it looked like the right path. I'm just not quite used to the new structure yet - the last version I used was v8. Appreciate the helpful advice! I've marked your last message as the solution.

    Many thanks!

Please Sign in or register to post replies

Write your reply to:

Draft