Kilhoffer
Kilhoffer

Reputation: 32904

Can you use multiple VaryByCustom parameters when caching a user control?

I've been trying this a couple of different ways, but it's not working for some reason. Is it even possible?

Upvotes: 7

Views: 2585

Answers (3)

Richard
Richard

Reputation: 1289

You can use multiple parameters by separating them by a semicolon, but you have to implement the logic of splitting them yourself. This means you can use any character as your separator, because you need to parse it yourself.

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

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

Extra note: base.GetVaryByCustomString doesn't implement any string splitting capabilities and will only do something when browser is passed as a value. Otherwise it will return null.

Upvotes: 0

Timothy Lee Russell
Timothy Lee Russell

Reputation: 3748

If you are overriding GetVaryByCustomString() in the Global.asax.cs file, you can pass in a semicolon delimited list of values which you then need to parse.

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

Upvotes: 4

user9991
user9991

Reputation: 576

Yes. Separate them in your declaration by semicolons.

Upvotes: 12

Related Questions