Is it possible to use asp.net page level caching with various parameters and localization

I would like to use page level caching on my asp.net page. vary depending on the parameters, but still the contents of the page are cached in the language of the original request. If the same url / param is requested, and the user views it in a different region than the first request (for example, French instead of English), the cache returns the contents of the page in the language of the original request (in English). Is there a way to cache the page depending on the value of the parameter and the value in the base page class (for example, as the property value returned from Thread.CurrentThread.CurrentUICulture.TwoLetterISOLanguageName)?

+4
source share
2 answers

In OutputCache, set VaryByCustom="Language" and update the 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 the cache depends on is your page culture.

+4
source

Using datacache you can specify a cache name. what i did when i had this problem i cache pagedata with pagename + localization as cachename

+1
source

All Articles