从数据库加载图片,提高效率,缓存

context.Response.ContentType = "image/jpg";
System.IO.FileInfo fi = new System.IO.FileInfo(context.Request.PhysicalPath);

string fileEtag = "\"" +UpdateTime + "\"";
string cacheETag = context.Request.Headers.Get("If-None-Match");

context.Response.AddHeader("Last-Modified", UpdateTime.ToString("r"));
context.Response.AddHeader("ETag", fileEtag);
context.Response.AddHeader("Cache-Control", "max-age");
if (fileEtag == cacheETag)
{
context.Response.Status = "304 Not Modified";
}
else
{
context.Response.Status = "200 OK";
context.Response.BinaryWrite((Byte[])Image);//Image是从数据库读取的二进制
}

posted @ 2014-03-25 11:20  飞仙天外  阅读(399)  评论(0编辑  收藏  举报