我想使用甜甜圈缓存的替换功能。
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");
}
答案 0 :(得分:2)
否则,如果您的问题是您希望根据不同的参数获得不同的输出,因为您在网站的不同位置使用输出替换,我担心唯一的方法是定义不同的功能或者只使用替换方法作为带参数的实际方法的存根。
答案 1 :(得分:1)
好吧,你可以在Session中存储你需要的任何参数。在方法GetTime中,可以通过HttpContext访问这些参数。