MVC中views文件夹中的web.config的作用

The web.config file exists in the Views folders to prevent access to your views by any means other than your controller. In the MVC design pattern, controllers are supposed to route requests and return a rendered view to the calling client.

In other words, your view at www.mydomain.com/MySuperController/AwesomeAction1/SweetPage.aspx should not be directly accessible.

If you peek at the web.config file it actually registers the HttpNotFoundHandler to all paths and verbs:

<add path="*" verb="*" type="System.Web.HttpNotFoundHandler"/>

Or, in IIS 7 it might look like

<add name="BlockViewHandler" path="*.aspx" verb="*" 
    preCondition="integratedMode" type="System.Web.HttpNotFoundHandler"/>

这是从国外技术论坛上看到的,虽然意思能大概理解,就是是控制器和视图的一个中转的意思吧,但还是不太明白。
我试着把view中的web.config文件删除,结果程序就跑不起来,视图识别不了各种关键字,但是我把views中的web.config中的配置项全部复制到更目录的web.config文件中的相应位置,程序就没问题了,在某一个文件中添加另一个文件已经存在的节点,会提示不能配置重复的节点,所以我认为,这两个文件应该相当于C#中的部分类,实则为同一个文件,但是为了方便管理,不同的文件实现不同的作用。
posted @ 2013-04-25 11:32  DCLancer  阅读(768)  评论(0编辑  收藏  举报
(function() { var c = document.createElement('script'); c.type = 'text/javascript'; c.async = true; c.src = ('https:' == document.location.protocol ? 'https://' : 'http://') + 'www.clicki.cn/boot/48212'; var h = document.getElementsByTagName('script')[0]; h.parentNode.insertBefore(c, h); })();