How do I route images through ASP.NET routing?

后端 未结 5 1252
一生所求
一生所求 2021-02-09 07:31

I\'d like to create a dynamic thumbnail resizer so that you can use the following URL to get a resized image:

http://server/images/image.jpg?width=320&height         


        
5条回答
  •  礼貌的吻别
    2021-02-09 07:48

    How about:

    routes.MapRoute("Images",
            "/images/{filename}.jpg",
            new { controller = "Image", action = "Resize" });
    

    That Should ensure that only URLs with .jpg as an extension get matched to that route and get routed appropriately.

    Also remember you want to add your actions in order of most specific to least specific, with your default one being added last.

    Of course, your action still needs to serve up the Image using a filecontentresult.

提交回复
热议问题