相关疑难解决方法(0)

ASPX返回图像 - 输出缓存能力?

问候!

我创建了一个APSX Web表单,它根据一些提供的参数返回一个远程图像.它可以像这样使用:

<img src="/ImageGetter.aspx?param1=abc&param2=123" />
Run Code Online (Sandbox Code Playgroud)

ImageGetter.aspx的标记和代码看起来类似于:

<%@ OutputCache Duration="100000" VaryByParam="*" Location="ServerAndClient" %>
<%@ Page Language="C#" AutoEventWireup="false" EnableSessionState="False" CodeBehind="ImageGetter.aspx.cs" Inherits="ACME.Helpers.ImageGetter" %>
Run Code Online (Sandbox Code Playgroud)

此代码在ImageGetter.aspx的Page_Load方法中调用:

byte[] data = null;
Dictionary<string, string> file_locations = GetImageLocations(param1, param2);
try
{
    data = new WebClient().DownloadData(file_locations["main"]);
}
catch (WebException wex)
{
    try
    {
        data = new WebClient().DownloadData(file_locations["backup"]);
    }
    catch (Exception e)
    {
        throw;
    }
}
Response.ContentType = "image/jpeg";
Response.OutputStream.Write(data, 0, data.Length);
Response.End();
Run Code Online (Sandbox Code Playgroud)

从我的测试来看,它似乎不是缓存.这可能与输出缓存有关,还是应该根据查询字符串参数编写自己的缓存来存储字节数组?

c# asp.net caching outputcache

6
推荐指数
1
解决办法
3213
查看次数

ASP.net缓存ASHX文件服务器端

鉴于通用处理程序:

<%@ WebHandler Language="C#" Class="autocomp" %>

using System;
using System.Text;
using System.Text.RegularExpressions;
using System.Web;
using System.Web.UI;

public class autocomp : IHttpHandler {

    public void ProcessRequest (HttpContext context) {

        context.Response.ContentType = "application/json";
        context.Response.BufferOutput = true;

        var searchTerm = (context.Request.QueryString["name_startsWith"] + "").Trim();

        context.Response.Write(searchTerm);
        context.Response.Write(DateTime.Now.ToString("s"));

        context.Response.Flush();
    }

    public bool IsReusable {
        get {
            return false;
        }
    }

}
Run Code Online (Sandbox Code Playgroud)

如何server side根据name_startsWith查询字符串参数缓存此文件1小时?使用Web用户控件很容易:

<%@ OutputCache Duration="120" VaryByParam="paramName" %>
Run Code Online (Sandbox Code Playgroud)

但我一直在寻找与通用handler(ashx)文件相同的一段时间,并找不到任何解决方案.

c# asp.net caching

2
推荐指数
1
解决办法
3774
查看次数

asp.net中的愚蠢缓存

我使用这样的代码

string.Format("<img src='{0}'><br>", u.Avatar);
Run Code Online (Sandbox Code Playgroud)

u.Avatar-它就像'/img/path/pic.jpg'

但在这个网站,我可以上传新的图像而不是旧的pic.jpg.所以图片新,但名字很旧.和浏览器显示OLD图片(缓存).如果我把随机数像/img/path/pic.jpg?123然后工作正常,但我只需要上传后,而不是总是.我怎么能解决这个问题?

asp.net caching image

0
推荐指数
1
解决办法
470
查看次数

标签 统计

asp.net ×3

caching ×3

c# ×2

image ×1

outputcache ×1