c# - ASP .NET - 替换和页面输出( donut )缓存 - 如何将自定义参数传递给 HttpResponseSubstitutionCallback 委托(delegate)

标签 c# asp.net donut-caching

我想使用 donut 缓存的替换功能。

public static string GetTime(HttpContext context)
{
    return DateTime.Now.ToString("T");
}

...

The cached time is: <%= DateTime.Now.ToString("T") %>
<hr />
The substitution time is:
<% Response.WriteSubstitution(GetTime); %>

...但我想将附加参数传递给 HttpContext 旁边的回调函数。
所以问题是:
如何将附加参数传递给 GetTime 回调?
例如,像这样:

public static string GetTime(HttpContext context, int newArgument)
{
    // i'd like to get sth from DB by newArgument
    // return data depending on the db values

    // ... this example is too simple for my usage
    if (newArgument == 1)
        return "";
    else
        return DateTime.Now.ToString("T");
}

最佳答案

否则,如果您的问题是您希望根据不同的参数获得不同的输出,因为您在网站的不同位置使用输出替换,恐怕唯一的方法是定义不同的函数或仅将替换方法用作带参数的实际方法的 stub 。

关于c# - ASP .NET - 替换和页面输出( donut )缓存 - 如何将自定义参数传递给 HttpResponseSubstitutionCallback 委托(delegate),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2533003/

相关文章:

c# - Mvc Donut Caching 以编程方式禁用缓存

caching - ASP.NET MVC 3 中是否提供 donut 缓存

c# - 无法从头开始使用命名空间创建新的 XDocument

c# - EPPlus 创建的 Excel 表不会将公式传播到新行

c# - 向本地域发送电子邮件

c# - 是否可以将 onclick() 事件应用于 span 标记?

c# - 我可以将 C# 中的 Javascript 函数添加到 gmail 电子邮件中吗?

c# - 加载与引用 .NET DLL 位于同一文件夹中的引用 .NET DLL 时出现 "Not found"异常

c# - 屏幕分辨率和滚动条