outstream.ashx
来自「一个不错的在线考试系统!~~实现了基本的在线考试系统的主要功能」· ASHX 代码 · 共 58 行
ASHX
58 行
<%@ WebHandler Language="C#" Class="OutStream" %>
using System;
using System.Web;
using System.Data;
using System.Data.SqlClient;
using System.IO;
using netextramSystem;
public class OutStream : IHttpHandler {
private SqlDbBase Db = new SqlDbBase();
public void ProcessRequest (HttpContext context) {
context.Response.ContentType = "image/jpeg";
context.Response.Cache.SetCacheability(HttpCacheability.Public);
context.Response.BufferOutput = false;
string loginID=null;
string type=null;
Stream stream = null;
if (context.Request.QueryString["id"] != null && context.Request.QueryString["type"] != null)
{
type = context.Request.QueryString["type"];
loginID = context.Request.QueryString["id"];
switch(type)
{
case "1":
stream = Db.RunScalar("photo","tb_stuinfo_学生","stuID='" + loginID + "'",null);
break;
case "2":
stream = Db.RunScalar("photo", "tb_teachinfo_教师", "teachID='" + loginID + "'", null);
break;
case "3":
stream = Db.RunScalar("photo", "tb_admininfo_管理员", "admID='" + loginID + "'", null);
break;
}
}
if (stream != null)
{
//定义字节缓存空间
const int buffersize = 1024 * 200;
byte[] buffer = new byte[buffersize];
int count = 0;
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 + =
减小字号Ctrl + -
显示快捷键?