开发者

is it possible to use asp.net page level caching with vary by param and localization

I would like to use page level caching on my asp.net page. vary by param works fine - however, the page content is cached in the language of the original request. If the same url / param is requested and the user is viewing in a different locale than the first request (French instead of English for example) - the cache returns the page content in the original request's language (English). Is there a way to cache the page based on the vary by param and a value in the bas开发者_开发技巧e page class (like as the property value returned from Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName)?


In the OutputCache set the VaryByCustom="Language" and update you Global.asax file to override the HttpApplication.GetVaryByCustomString Method by adding the following code:

public override string GetVaryByCustomString(HttpContext context, string custom)
    {
        if (custom.Equals("Language"))
        {
            return System.Threading.Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName;
        }
        else
        {
            return base.GetVaryByCustomString(context, custom);
        }
    }

This code will make the parameter that the cache depends on is your page culture.


With datacache you can specify the cache name. what I did when I had this problem I caches the pagedata with pagename + localisation as cachename

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜