6
votes

I have the following in my Razor view for an editor template in my Orchard module:

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

When the page is rendered I can see this line at the bottom:

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

Beautiful! Only problem is, when I visit that path I get a 404 error. The script doesn't exist.

...but it does! It's saved as Orchard.Web\Modules\MyModuleName\Scripts\assets.js

The rest of my module's functionality works fine - I can enable and use it, it just won't find the script file. Am I missing something obvious here?!

2
I assume the capitalization of /Scripts/ vs. /scripts/ is not the issue?AlexMA
Hi @Alex, tried it with both :(greg84
Do you have a web.config in your scripts folder with the right permissions?forsvarir
Ha! No! +1 for you, and @forsvarir for the answer :)greg84

2 Answers

9
votes

By default, Orchard is setup to restrict folder permissions. This is usually overriden by adding a web.config to each folder as required (in this case, your scripts folder).

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

The codegenned web.config looks like this:

<?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>
2
votes

I found an other reason for this 404 which I would like to mention. UrlScan by default rejects a dot in the path, I found this in my log: Rejected URL+contains+dot+in+path

So change the setting in:

AllowDotInPath=1

and it works again. It took me some time to find this, because I never use a dot in path...