加入收藏 | 设为首页 | 会员中心 | 我要投稿 大庆站长网 (https://www.0459zz.com/)- 科技、智能边缘云、事件网格、云计算、站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net-mvc – ASP.NET MVC路由和静态数据(即图像,脚本等)

发布时间:2020-08-02 02:04:05 所属栏目:asp.Net 来源:互联网
导读:如果我在ASP.NET MVC1(或2)Web应用程序中为静态资源请求资源,请说…图像或 javascript文件或css文件… .NET框架是否尝试查看如果请求匹配路由列表…并最终找不到它的控制器? 例如. 资源:/Content/Images/Foo.png 此请求是否通过我的路由列表..无法将任何控

如果我在ASP.NET MVC1(或2)Web应用程序中为静态资源请求资源,请说…图像或 javascript文件或css文件… .NET框架是否尝试查看如果请求匹配路由列表…并最终找不到它的控制器?

例如.

资源:/Content/Images/Foo.png

此请求是否通过我的路由列表..无法将任何控制器/操作与此请求匹配,然后直接尝试该路径?

解决方法

您可以选择是否映射现有文件或不设置 RouteCollection.RouteExistingFiles属性

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

这是我从here读到的内容:

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

(编辑:大庆站长网)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读