0

一部のユーザーがpng、jpeg、gifなどの拡張子を持つ画像ファイルにアクセスしたときに、httphandlerを実行したいと思います。しかし、パスしようとするとエラー 404 が発生します。どのサーバーがディスク上のファイルを見つけようとしていると思いますが、ハンドラー内のファイルへのアクセスにはエイリアスを使用し、実際の物理ファイルパスには新しいアクセスを使用したいと考えています。
構成ファイルの例:

<configuration>
  <system.web>
    <compilation debug="true" targetFramework="4.0" />
    <httpHandlers>
      <add verb="GET,HEAD" path="*.jpg" type="Startup.Shop.ImageHandler, Startup.Shop" validate="false"/>
    </httpHandlers>
    <authorization>
      <allow users="*" />
    </authorization>
  </system.web>
  <system.webServer>
    <handlers>
      <add name="ImageHandlerfor JPG" path="*.jpg" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
      <add name="ImageHandler for GIF" path="*.gif" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
      <add name="ImageHandler for BMP" path="*.bmp" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
      <add name="ImageHandler for PNG" path="*.png" verb="GET" type="Startup.Shop.ImageHandler, Startup.Shop" resourceType="Unspecified" />
    </handlers>
  </system.webServer>
/configuration>

ハンドラー クラスの例:

 public class ImageHandler : IHttpHandler, IRouteHandler
    {

        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/plain";
            context.Response.Write("Hello World");
        }

        public bool IsReusable
        {
            get
            {
                return false;
            }
        }

        public IHttpHandler GetHttpHandler(RequestContext requestContext)
        {
            return this;
        }
    }

その他 - クラシック モードとして構成された iis サーバー

4

1 に答える 1