MVC 3将不会为从区域子文件夹的内容的文件 [英] MVC 3 Won't Serve Content files from Areas subfolder

查看:197
本文介绍了MVC 3将不会为从区域子文件夹的内容的文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一对夫妇的领域和便携式领域的应用MVC3以及(使用MVCContrib)

I have an MVC3 application with a couple of areas and a portable area as well (using MVCContrib)

通常情况下,我把我所有的内容文件在〜/内容和我的脚本在〜/脚本。

Normally, I keep all my content files under ~/Content and my scripts under ~/Scripts.

不过,我建立一个相当复杂的Web客户机到我的网站上其他服务,我要组织这些JavaScript和图像文件的文件区的文件夹结构,它看起来像这样下(图像文件和资源的地段),下〜 /地区/ Web客户端

However, I am building a fairly complex webclient to another service on my site and I want to organize those javascript and image files (LOTS of image files and resources) under the Area's folder structure, which looks something like this, under ~/Areas/WebClient


  • 内容

    • CSS

    • 字体

    • 图片

    • JS​​

    我有一个资源聚合器(我的便携式领域之一),即能达到进入CSS / JS文件夹就好提供这些内容。然而,CSS文件直接引用图像/字体文件夹和所有这些环节出现断裂。我有双重和三重检查的路径,并确保一切是正确的,但我仍然得到404错误。

    I have a resource aggregator controller (one of my portable areas) that is able to reach into the CSS/JS folders just fine to provide that content. However, the CSS files reference the images/fonts folders directly and all of those links show up broken. I have double and triple checked the paths and made sure everything was right but I still get 404 errors.

    据我所知MVC3应该忽略,只要有一个静态文件存在路由。此外,据我所知,只有APP_ *文件夹中享受特别保护。我在想什么?我宁愿没有我的图片和资源,我的主要应用程序中混合,如果我能在所有的避免它。

    As far as I know MVC3 is supposed to ignore routing so long as there's a static file there. Also, as far as I know, only the App_* folders enjoy special protection. What am I missing? I'd rather not mix in my images and resources with my main application if I can at all avoid it.

    例如:<一href=\"http://localhost/Areas/WebClient/Content/images/knownimage.png\">http://localhost/Areas/WebClient/Content/images/knownimage.png将无法正常工作,而应该的,因为它的存在!

    As an example: http://localhost/Areas/WebClient/Content/images/knownimage.png will not work, but should, as it exists!

    推荐答案

    于是经过一番睡眠,更重要的是,辞去我想起MVC确实能使问题远离你提供保护的人直接下载观点,害得我记得在区文件夹中所需的Web.config文件。果然,有,基本上将所有请求发送到FileNotFound处理一个HttpHandler。

    So after some sleep and, more importantly, stepping away from the problem I remembered that MVC does in fact offer you protection from people downloading views directly, which led me to remember the Web.config file required in the Areas folder. Sure enough, there's an httphandler that basically sends all requests to the FileNotFound handler.

    我所要做的就是在我想用下面揭露的内容文件夹拖放web.config文件:

    All I had to do was drop a web.config file in the content folder I wanted to expose with the following:

    <?xml version="1.0" encoding="utf-8"?>
    <configuration>  
      <system.webServer>
        <validation validateIntegratedModeConfiguration="false" />
        <handlers>
          <remove name="BlockViewHandler" />     
        </handlers>
      </system.webServer>
    </configuration>
    

    问题解决了。

    这篇关于MVC 3将不会为从区域子文件夹的内容的文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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