Resize and Display image from server with ASP.NET

后端 未结 5 1992
轮回少年
轮回少年 2021-01-13 17:23

Got a question. I have images hosted on my server. I already know of the method when an image is uploaded to resize it and save, but I have another thought in mind.

<
5条回答
  •  无人及你
    2021-01-13 17:46

    You can create an implementation of IHttpHandler to respond to image requests, in that handler you can have code that loads the image from disk and transforms to it a size that is needed. You need to return the proper mime type with the response, and use the WriteBytes method (or something like it, I forgot the name). Also, you may look into content expiration headers, so that the image may not have to be loaded every time by the same client, but is instead cached.

提交回复
热议问题