简体   繁体   English

如何在asp.net中使用图像处理程序显示图像

[英]How to show images using image handler in asp.net

I recently decided to create my thumbnails using Image Handler.I mean using such as this address: 我最近决定使用Image Handler创建缩略图,我的意思是使用这样的地址:

  <img src="Flower1.png?width=100&height=300"/>

I Googled it and reached no result. 我用Google搜索,但没有结果。 Most of tutorials said somehow that i should use like this address: 大多数教程都以某种方式表示我应该使用以下地址:

<img src="GetImage.ashx?file=~/Flower1.png&width=100&height=300"/>

But i dont want to use this address. 但是我不想使用这个地址。 And some tutorials which used my desired way, are too old to set IIS. 有些使用我期望的方法的教程太旧了,无法设置IIS。 Thanks for guidance. 感谢您的指导。

Your question is pretty broad, but basically: under the covers you are going to need to have a asp.net handler, ie the GetImage.asxh file that will serve up the images - plenty of examples that you can google to find out how to do that, and once you have that working you can setup IIS redirect rules that will map the requests that come in as: 您的问题很广泛,但基本上是这样:在幕后,您将需要有一个asp.net处理程序,即用于提供图像的GetImage.asxh文件-您可以在Google上查找大量示例来了解如何然后,您就可以设置IIS重定向规则,将这些请求映射为:

<img src="Flower1.png?width=100&height=300"/>

to

<img src="GetImage.ashx?file=~/Flower1.png&width=100&height=300"/>

Redirect rules starter: 重定向规则启动器:

http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module http://www.iis.net/learn/extensions/url-rewrite-module/creating-rewrite-rules-for-the-url-rewrite-module

The user/website will only see the images with the standard urls that you want, but under-the-covers the redirection will take place and your handler can resize the images as needed on request. 用户/网站将仅看到具有所需标准URL的图像,但是在隐藏的情况下,将进行重定向,并且您的处理程序可以根据需要调整图像的大小。

You have to define, in the web.config, that you want for the path "Flower1.png" to use a specific Handler. 您必须在web.config中定义要使用特定处理程序的路径“ Flower1.png”。 For example: 例如:

<?xml version="1.0" encoding="utf-8" ?>
<configuration>
  <system.web>
    <httpHandlers>
        <!-- ImageHandler handlers -->
        <add verb="*" path="*Flower1.png" 
         type="skmHttpHandlers.ImageHandler, skmHttpHandlers" />
    </httpHandlers>
  </system.web>
</configuration>

This will set that for the "*Flower1.png" file, instead of sending the file itself, it'll run a http handler. 这将为“ * Flower1.png”文件设置该文件,而不是发送文件本身,而是运行一个http处理程序。

You can check this MSDN page for more details. 您可以检查此MSDN页面以获取更多详细信息。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM