关于ASP.NET MVC和静态数据(即图片,脚本等)问题 [英] Question about ASP.NET MVC and static data (ie. images, scripts, etc)

查看:359
本文介绍了关于ASP.NET MVC和静态数据(即图片,脚本等)问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有我的ASP.NET MVC1为静态资源的资源(或2)Web应用程序的请求,说...图像或JavaScript文件或CSS文件...做了.NET框架尝试,看看如果请求的路径列表匹配......并最终为它无法找到控制器?

If i have a request for a resource in my ASP.NET MVC1 (or 2) web app for a static resource, say ... an image or a javascript file or a css file ... does the .NET framework try and see if the request matches the route list ... and eventually can't find a controller for it?

如:

来源:/Content/Images/Foo.png

Resource: /Content/Images/Foo.png

这是否要求通过我的路由表..不匹配任何控制器/行动,这个请求,然后..我...唐诺直接尝试这条道路?

Does this request go through my route list .. fails to match any controllers / actions to this request and then .. i donno ... attempt that path directly?

推荐答案

您可以选择是否映射现有的文件或不设置<一个href=\"http://msdn.microsoft.com/en-us/library/system.web.routing.routecollection.routeexistingfiles.aspx\"><$c$c>RouteCollection.RouteExistingFiles地产

You can choose whether to map an existing file or not setting the RouteCollection.RouteExistingFiles Property

获取或设置一个值,指示
  是否ASP.NET路由应处理
  匹配现有文件的URL。

Gets or sets a value that indicates whether ASP.NET routing should handle URLs that match an existing file.

下面是我从读到这里

However, the routing system still does check the file system to see if an
incoming URL happens to match a file or disk, and if so, routing ignores the request (bypassing
any route entries that the URL might also match) so that the file will be served directly.
This is very convenient for static files, such as images, CSS, and JavaScript files. You can
keep them in your project (e.g., in your /Content or /Script folders), and then reference and
serve them directly, just as if you were not using routing at all. Since the file genuinely exists
on disk, that takes priority over your routing configuration.

If, instead, you want your routing configuration to take priority over files on disk, you can set
the RouteCollection’s RouteExistingFiles property to true. (It’s false by default.)

这篇关于关于ASP.NET MVC和静态数据(即图片,脚本等)问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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