Orchard CMS:即使存在Javascript文件也返回404找不到 [英] Orchard CMS : Javascript file returns 404 not found even though it exists

查看:68
本文介绍了Orchard CMS:即使存在Javascript文件也返回404找不到的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

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

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

...但是可以!它另存为Orchard.Web\Modules\MyModuleName\Scripts\assets.js

...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?!

推荐答案

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

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).

如果您使用codegen模块生成模块,那么将在生成过程中为您完成此操作.如果不是,那么您需要自己添加web.config.

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.

代码生成的web.config看起来像这样:

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>

这篇关于Orchard CMS:即使存在Javascript文件也返回404找不到的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆