Can you use several VaryByCustom options when caching a custom control?

I tried this in several different ways, but for some reason it does not work. Is it possible?

+7
caching
source share
3 answers

Yes. Separate them in your ad with a semicolon.

+12
source share

If you override GetVaryByCustomString () in the Global.asax.cs file, you can pass a comma-delimited list that you need to parse.

There is one built-in value (Browser) that will be used if the specified attribute does not exist.

+4
source share

You can use several parameters, separating them with a semicolon, but you must implement the logic for splitting them. This means that you can use any character as a separator, because you need to parse it yourself.

You are probably overriding GetVaryByCustomString(HttpContext context, string custom) in your global.asax. The custom parameter will contain everything you pass using VaryByCustom , like this

 <%@ OutputCache Duration="86400" VaryByParam="none" VaryByCustom="custom1;custom2" %> 

Note: base.GetVaryByCustomString does not implement any line splitting capabilities and will do something only when the browser is passed as a value. Otherwise, it will return null .

0
source share

All Articles