我也遇到了类似的问题:Using ASP.NET routing to serve static files
在RouteConfig中,我添加了以下行:
routes.Add(“图像ABC",新路径(”图像/abc/{*文件名}“,新ImageRouteHandler("abc") ); routes.Add(“图片集XYZ”、新路线(“图文/xyz/{*filename}”、新ImageRouteHandler(“xyz”);
我在这里找到了一个相当不错的ImageRouteHandler实现:http://www.phpvs.net/2009/08/06/aspnet-mvc-how-to-route-to-images-or-other-file-types/,我只是在ctor中添加了一个参数来构建物理路径.
约束:除了ABC或XYZ之外,我在Images中还有其他路径,我不想被路由。
注意:我使用{*filename},所以我可以引用多个片段.更多信息在这里:pattern
问题:
Images/[abc|xyz]/...。- a) if the code is placed above of default routing, it will mess up the RedirectToAction
- b) and if the code is placed below the default routing, it won't handle the immediate routing, ex. `Images/abc/img.jpg` won't be handled, but `Images/abc/level1/level2/level3/img.jpg` will be handled
为什么?不知道。
发布于 2013-12-04 16:23:39
固定于:
IRouteConstraint。两件事..。只接受IncomingRequest,并检查文件夹是abc还是xyz。来源:After add MapPageRoute to an asp.net mvc project, the site stops to enter in Home ControllerRoutes.Add(“图像特殊”、新路径(“图像/{文件夹} /{*文件名}”)、null、新RouteValueDictionary {“传出”、新ImageRouteConstraint() }、新ImageRouteHandler() );
ImageHandler使之看起来更好看。资料来源:http://weblogs.asp.net/fredriknormen/archive/2007/11/18/asp-net-mvc-framework-create-your-own-iroutehandler.aspx和Dynamically Rendering asp:Image from BLOB entry in ASP.NEThttps://stackoverflow.com/questions/20363471
复制相似问题