简体   繁体   English

如何处理带有图像扩展的路由

[英]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.

相关问题 如何注册一个httphandler以处理IIS中的所有扩展? - how to register a httphandler to handle all extensions in IIS? ASP.net如何处理没有路由的URL路径? - How does ASP.net handle URL paths that have no routes? ASP.NET 核心带 SPA,如何处理 root 上的无效路由? - ASP.NET Core with SPA, how to handle invalid routes on root? 如何处理多个图像上传 - How to handle multiple image uploads Gridview格式字段作为电话号码,但有些结果是4位数的扩展,如何处理? - Gridview Format Field as Phone Number but some results are 4 digit extensions, how to handle? 如何使用购买服务来处理Google验证码图片 - How to handle Google captcha image using purchase service for handle captcha 当一个有整数参数而另一个有字符串时,如何处理类似的路由? - How to handle similar routes when one has integer parameter and other has string? 如何让单个控制器和动作处理 asp.net core 中的所有路由? - how to have a single controller and action handle all routes in asp.net core? 如何在ASP.NET MVC中具有通用路由,但处理未知操作? - How to have generic routes in ASP.NET MVC, but handle unknown actions? 注册带有MVC扩展名的路线和区域时,MVC区域不显示 - MVC areas not diplaying when registering routes and areas with MVC extensions
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM