Orchard CMS:Javascript文件返回404找不到,即使它存在

gre*_*g84 6 javascript orchardcms http-status-code-404

我的Razor视图中有以下内容,用于我的Orchard模块中的编辑器模板:

Script.Include("assets.js").AtFoot();
Run Code Online (Sandbox Code Playgroud)

渲染页面时,我可以在底部看到这一行:

<script src="/Modules/MyModuleName/scripts/assets.js" type="text/javascript"></script>
Run Code Online (Sandbox Code Playgroud)

美丽!唯一的问题是,当我访问该路径时,我收到404错误.该脚本不存在.

......但确实如此!它被保存为Orchard.Web\Modules\MyModuleName\Scripts\assets.js

我的模块的其余部分功能正常 - 我可以启用和使用它,它只是找不到脚本文件.我错过了一些明显的东西吗?!

for*_*rir 8

默认情况下,Orchard设置为限制文件夹权限.这通常通过根据需要向每个文件夹添加web.config(在本例中为您的脚本文件夹)来覆盖.

如果您使用codegen模块生成模块,那么这将作为生成的一部分为您完成.如果没有,那么您需要自己添加web.config.

codegenned web.config如下所示:

<?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>
Run Code Online (Sandbox Code Playgroud)