[英]How to handle routes with image extensions
I have action:我有行动:
public ActionResult Thumbnail(string image)
{
return GetThumbnail(image);
}
I am trying to access it with the next request:我正在尝试通过下一个请求访问它:
http://localhost:60955/thumbnail/imagename.png
In config I have:在配置中我有:
<add name="Png" path="/thumbnail/*.png" verb="GET" type="System.Web.Handlers.TransferRequestHandler" preCondition="integratedMode,runtimeVersionv4.0" />
And in routes configuration:在路由配置中:
routes.MapRoute(
name: "Thumbnail",
url: "thumbnail/{*image}",
defaults: new { controller = "Image", action = "Thumbnail" }
);
So it works for the above image URL.所以它适用于上面的图像 URL。 But I need this to work for any subfolder and the following returns 404:
但我需要它适用于任何子文件夹,以下返回 404:
http://localhost:60955/thumbnail/screenshots/imagename.png
And when I add slash it works again:当我添加斜线时,它再次起作用:
http://localhost:60955/thumbnail/screenshots/imagename.png/
Can I make it work with no trailing slash?
我可以让它在没有斜杠的情况下工作吗? I feel like I need to customize the handler path in the config but cannot figure out how.
我觉得我需要在配置中自定义处理程序路径,但无法弄清楚如何。
You should use query string for this case您应该在这种情况下使用查询字符串
URL change to this URL 改成这个
http://localhost:60955/thumbnail?image=screenshots/imagename.png
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.