开发者

Set Page Output Cache VaryByCustom value programmatically

开发者 https://www.devze.com 2022-12-26 19:20 出处:网络
I w开发者_StackOverflow社区ant to use an Enum value for the types of VaryByCustom parameters I will support, is it possible to do this?

I w开发者_StackOverflow社区ant to use an Enum value for the types of VaryByCustom parameters I will support, is it possible to do this?

I tried setting it in the page itself

<%@ OutputCache Duration="600" VaryByParam="none" 
            VaryByCustom='<%=VaryByCustomType.IsAuthenticated.ToString(); %>' %>

But this returned the entire literal string "<%=VaryByCustomType.IsAuthenticated.ToString(); %>" inside my global.asax is there any way to do this either on the page itself or from the codebehind? Or is this just something I have to accept is purely magic strings and nothing I can do to add type safety to it?


Instead of using the @Outputcache directive, try doing it with code in the page. e.g.

void Page_Init() {
    var outputCacheSettings = new OutputCacheParameters() {
        Duration = 600,
        VaryByCustom = VaryByCustomType.IsAuthenticated.ToString()
    };
    InitOutputCache(outputCacheSettings); 
}
0

精彩评论

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