Orchard CMS: Javascript file returned 404 not found, although it exists

My Razor view for the editor template in my Orchard module has the following:

Script.Include("assets.js").AtFoot(); 

When the page is displayed, I see this line below:

 <script src="/Modules/MyModuleName/scripts/assets.js" type="text/javascript"></script> 

Beautiful! The only problem is that when I visit this path, I get a 404. error. The script does not exist.

... but it is so! It is saved as Orchard.Web\Modules\MyModuleName\Scripts\assets.js

The rest of the functions of my module work fine - I can turn it on and use it, it just won’t find the script file. Did I miss something obvious here ?!

+6
source share
2 answers

By default, Orchard is configured to restrict folder permissions. This is usually overridden by adding the web.config file to each folder as needed (in this case, your script folder).

If you use the codegen module to create your own module, then this is done for you as part of a generation. If not, then you need to add web.config yourself.

The designated web.config is as follows:

 <?xml version="1.0" encoding="UTF-8"?> <configuration> <appSettings> <add key="webpages:Enabled" value="false" /> </appSettings> <system.web> <httpHandlers> <!-- iis6 - for any request in this location, return via managed static file handler --> <add path="*" verb="*" type="System.Web.StaticFileHandler" /> </httpHandlers> </system.web> <system.webServer> <staticContent> <clientCache cacheControlMode="UseMaxAge" cacheControlMaxAge="7.00:00:00" /> </staticContent> <handlers accessPolicy="Script,Read"> <!-- iis7 - for any request to a file exists on disk, return it via native http module. accessPolicy 'Script' is to allow for a managed 404 page. --> <add name="StaticFile" path="*" verb="*" modules="StaticFileModule" preCondition="integratedMode" resourceType="File" requireAccess="Read" /> </handlers> </system.webServer> </configuration> 
+8
source

I found another reason for this 404 that I would like to mention. UrlScan by default rejects a point in the path, I found this in my log: Rejected URL + contains + point + in + paths

So, change the setting to:

 AllowDotInPath=1 

and it works again. It took me a while to find this because I never use a point in the way ...

+2
source

Source: https://habr.com/ru/post/910797/


All Articles