Outputting an image from an HttpHandler (C#) : HTTP Modules « Development « ASP.NET Tutorial






<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">

<html xmlns="http://www.w3.org/1999/xhtml" >
<head id="Head1" runat="server">
    <title>HttpHandler Serving an Image</title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
        <img src="ImageHandler.ashx" />
    </div>
    </form>
</body>
</html>

File: Handler.ashx


<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;

public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "image/jpeg"
        context.Response.WriteFile("Sunset.jpg")
    }
 
    public bool IsReusable {
        get {
            return false;
        }
    }

}








9.25.HTTP Modules
9.25.1.Creating Custom HTTP Modules
9.25.2.HttpContext (C#)
9.25.3.HttpContext (VB)
9.25.4.URL rewriting HttpModule (C#)
9.25.5.URL rewriting HttpModule (VB)
9.25.6.The IHttpHandler page template (C#)
9.25.7.The IHttpHandler page template (VB)
9.25.8.Outputting an image from an HttpHandler (C#)
9.25.9.Outputting an image from an HttpHandler (VB)
9.25.10.Adding the HttpHandler configuration information to web.config
9.25.11.HttpModule Tester