一、自定义图片输出,启用客户端的图片缓存处理
代码示例:
string path = Request.Url.LocalPath;
if (path != null)
{
path = path.ToLower();
if (path.Contains("uploadfiles") || path.Contains("ueditor/net/upload"))
{
path = Server.MapPath(path).Replace("LiuXue.Mobile", "LiuXue.Web");
//输出主站内容
if (File.Exists(path))
{
//自定义缓存处理
Response.ContentType = "image/jpeg";
Response.Headers["Cache-Control"] = "public"; //指定客户端,服务器都处理缓存
int length = path.LastIndexOf(".") - path.LastIndexOf("/") - ;
Response.Headers["Etag"] = path.Substring(path.LastIndexOf("/") + , length);
Response.Headers["Last-Modified"] = new DateTime().ToString("r");
Response.Headers["Content-Length"] = new FileInfo(path).Length.ToString();
Response.Headers["Accept-Ranges"] = "bytes"; Response.TransmitFile(path);
Response.End();
}
}
}
更多: