How do I route images through ASP.NET routing?

后端 未结 5 1268
一生所求
一生所求 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条回答
  •  Happy的楠姐
    2021-02-09 07:39

    The simplest way would be to route all images through the controller and store your images in a separate location

    routes.MapRoute("Images",
                "/images/{filename}",
                new { controller = "Image", action = "Resize" });
    
    /sitebase/images/image.jpg         //public image location
    /sitebase/content/images/image.jpg //real image location
    

    Your controller would then see which image was being requested and load the appropriate file from the file system. This would allow you to do what you want without any special handling.

提交回复
热议问题