相关疑难解决方法(0)

缓存ASHX图像响应

我已经创建了一个ashx文件来动态生成图像缩略图.我想在第一次调用它们后将这些图像缓存在客户端.

网址:

〜/ image.ashx?DIR =用户W = 25 H = 25&力= YES&IMG = matt.jpg

代码背后:

public void ProcessRequest (HttpContext context) {
    TimeSpan refresh = new TimeSpan(0, 15, 0);
    context.Response.Cache.SetExpires(DateTime.Now.Add(refresh));
    context.Response.Cache.SetMaxAge(refresh);
    context.Response.Cache.SetCacheability(HttpCacheability.Server);
    context.Response.CacheControl = HttpCacheability.Public.ToString();
    context.Response.Cache.SetValidUntilExpires(true);

    string dir = context.Request.QueryString["dir"];
    string img = context.Request.QueryString["img"];
    bool force = context.Request.QueryString["force"] == "yes";
    double w = 0;
    double h = 0;
    ...
    context.Response.ContentType = "image/jpeg";
    thumb.Save(context.Response.OutputStream, System.Drawing.Imaging.ImageFormat.Jpeg);
}
Run Code Online (Sandbox Code Playgroud)

使用Chrome中的开发工具我可以看到以下响应标头:

HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
Date: Mon, 26 Sep 2011 19:17:31 GMT
X-AspNet-Version: 4.0.30319 …
Run Code Online (Sandbox Code Playgroud)

c# caching image-processing ashx asp.net-4.0

4
推荐指数
1
解决办法
5900
查看次数

标签 统计

ashx ×1

asp.net-4.0 ×1

c# ×1

caching ×1

image-processing ×1