1、自定義圖片輸出,啓用客戶端的圖片緩存處理html
代碼示例:緩存
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("/") - 1; Response.Headers["Etag"] = path.Substring(path.LastIndexOf("/") + 1, length); Response.Headers["Last-Modified"] = new DateTime(2018).ToString("r"); Response.Headers["Content-Length"] = new FileInfo(path).Length.ToString(); Response.Headers["Accept-Ranges"] = "bytes"; Response.TransmitFile(path); Response.End(); } } }
更多:服務器