使用handler"不落地"返回图片信息

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

using System;
using System.IO;
using System.Web;

public class Handler : IHttpHandler {

    
public bool IsReusable {
        
get {
            
return true;
        }

    }

    
    
public void ProcessRequest (HttpContext context) {
        context.Response.ContentType 
= "image/jpeg";
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.BufferOutput 
= false;
        
        
try
        
{
            
string sno = context.Request.QueryString["sno"];

            
byte[] buffer = GetPhoto(sno);

            
if (buffer != null)
            
{
                context.Response.OutputStream.Write(buffer, 
0, buffer.Length);
            }

            
else
            
{
                context.Response.WriteFile(
"Images/nophoto.jpg");
            }

        }

        
catch (Exception ex){
            context.Response.Write(ex);
        }

    }

}
posted @ 2006-12-31 13:34  Liren  阅读(437)  评论(0编辑  收藏  举报