开发者

ASP .NET - Substitution and page output (donut) caching - How to pass custom argument to HttpResponseSubstitutionCallback delegate

开发者 https://www.devze.com 2022-12-24 04:41 出处:网络
I would like to use substitution feature of donut caching. public static string GetTime(HttpContext context)

I would like to use substitution feature of donut caching.

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); %>

...But I would like to pass additional parameter to callback function beside HttpContext.

so the question is:

How to pass additional argument to GetTime callback?

for instance, something like this:

public static string GetTime(HttpContext context, int newArgume开发者_运维问答nt)
{
    // 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");
}


Otherwise, if your problem is that you want to have different outputs based on different arguments because you're using the output substitution in different places on your website, I'm afraid the only way is to either define different functions or to only use the substitution methods as a stub for the actual method with arguments.


Well, you can store any argument you need in the Session. In method GetTime, these arguments can be accessed through the HttpContext.

0

精彩评论

暂无评论...
验证码 换一张
取 消