您的位置:首页 > 理论基础 > 计算机网络

HttpHandler动态生成图片

2015-07-06 14:52 561 查看
在Web1站点下存一张图片1.gif:测试站点中的图片输出到Http响应输出流;

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Web;

namespace Web1
{
/// <summary>
/// ContentTypeTest 的摘要说明
/// </summary>
public class ContentTypeTest : IHttpHandler
{

public void ProcessRequest(HttpContext context)
{
context.Response.ContentType = "image/gif";
string FilePath = context.Server.MapPath("~/1.gif");
using(Stream instream=File.OpenRead(FilePath))//new FileStream(....);
{
instream.CopyTo(context.Response.OutputStream);
}

}

public bool IsReusable
{
get
{
return false;
}
}
}
}


1、浏览器不知道服务器上有1.gif的存在,浏览器只是,发请求,就收请求,显示图片,其他的就是一概不知~!!(这个要想明白!!)
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: