⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 handler.ashx

📁 asp.net 做的个人图书站点应用
💻 ASHX
字号:
<%@ WebHandler Language="C#" Class="Handler" %>

using System;
using System.Web;
using System.IO;
//
//一般应用处理程序,主要处理从数据库读取图像字节关显示在网站上
//
public class Handler : IHttpHandler {
    
    public void ProcessRequest (HttpContext context) {
        context.Response.ContentType = "image/jpeg";
        context.Response.Cache.SetCacheability(HttpCacheability.Public);
        context.Response.BufferOutput = false;
        ImageSize size;
        switch (context.Request.QueryString["Size"])
        {
            case "S":
                size = ImageSize.Small;
                break;
            case "M":
                size = ImageSize.Large;
                break;
            default :
                size = ImageSize.Small;
                break; 
        }
        
        int id = -1;
        Stream stream = null;
        if (context.Request.QueryString["BookID"] != null && context.Request.QueryString["BookID"] != "")
        {
            id = Convert.ToInt32(context.Request.QueryString["BookID"]);
            stream = BookManager.GetBookImage(id, size);

        }
        else
        {
            id = Convert.ToInt32(context.Request.QueryString["CategoryID"]);
            stream = BookManager.GetClassImage(id, size);
        }
        if (stream == null)
            stream = BookManager.GetImage(size);
        const int buffersize=1024*16;
        byte[] buffer = new byte[buffersize];
        int count = stream.Read(buffer, 0, buffersize);
        while (count > 0)
        {
            context.Response.OutputStream.Write(buffer, 0, count);
            count = stream.Read(buffer, 0, buffersize); 
        }
        
    }
 
    public bool IsReusable {
        get {
            return true ;
        }
    }

}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -