ASP.NET MVC 路由和静态数据(即图像、脚本等)
如果我在 ASP.NET MVC1(或 2)Web 应用程序中请求静态资源,例如...图像、javascript 文件或 css 文件....NET 框架是否会尝试查看如果请求与路由列表匹配...并且最终找不到它的控制器?
例如。
资源:/Content/Images/Foo.png
此请求是否通过我的路由列表..无法将任何控制器/操作与此请求匹配,然后直接尝试该路径?
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?
eg.
Resource: /Content/Images/Foo.png
Does this request go through my route list .. fails to match any controllers / actions to this request and then attempt that path directly?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以选择是否映射现有文件或不设置
RouteCollection.RouteExistingFiles
属性以下是我从此处读到的内容:
You can choose whether to map an existing file or not setting the
RouteCollection.RouteExistingFiles
PropertyHere is what I read from here:
默认情况下,路由引擎将忽略服务器上物理存在的所有文件的路由映射。简而言之,您无需为 MVC 应用程序执行任何操作即可链接到静态文件。
By default the routing engine will ignore route maps for all files that exist physically on the server. In short, you need to do nothing for a MVC app to link to static files.
您还可以在 IIS 中做一些小技巧。我将 js、图像、css 等存储在虚拟目录下的 Content 文件夹中。
如果您随后查看内容文件夹的属性(在 IIS 管理器中),请将其创建为虚拟目录,然后删除通配符映射。然后将 Content 文件夹设置回普通目录。然后,这应该会停止由 aspnet_isapi 处理程序处理的对这些文件的请求。
You can also do a little trick in IIS. I store my js, images, css etc in the Content folder underneath the virtual directory.
If you then view properties (in IIS manager) of the Content folder, create it as a virtual directory, then remove the Wildcard mapping. Then set the Content folder back to a normal directory. This should then stop requests to these files being handled by the aspnet_isapi handler.