缓存用户控件时可以使用多个VaryByCustom参数吗?

时间:2021-04-20 21:20:07

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

我一直在尝试这几种不同的方式,但由于某些原因它不起作用。它甚至可能吗?

3 个解决方案

#1


12  

Yes. Separate them in your declaration by semicolons.

是。用分号在声明中分隔它们。

#2


4  

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.

如果要覆盖Global.asax.cs文件中的GetVaryByCustomString(),则可以传入以分号分隔的值列表,然后需要对其进行解析。

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

如果指定的属性不存在,将使用一个内置值(浏览器)。

#3


0  

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

您可能在global.asax中覆盖了GetVaryByCustomString(HttpContext上下文,字符串自定义)。自定义参数将包含您使用VaryByCustom传递的任何内容,如下所示

<%@ 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.

额外注意:base.GetVaryByCustomString不实现任何字符串拆分功能,只会在浏览器作为值传递时执行某些操作。否则它将返回null。

#1


12  

Yes. Separate them in your declaration by semicolons.

是。用分号在声明中分隔它们。

#2


4  

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.

如果要覆盖Global.asax.cs文件中的GetVaryByCustomString(),则可以传入以分号分隔的值列表,然后需要对其进行解析。

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

如果指定的属性不存在,将使用一个内置值(浏览器)。

#3


0  

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

您可能在global.asax中覆盖了GetVaryByCustomString(HttpContext上下文,字符串自定义)。自定义参数将包含您使用VaryByCustom传递的任何内容,如下所示

<%@ 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.

额外注意:base.GetVaryByCustomString不实现任何字符串拆分功能,只会在浏览器作为值传递时执行某些操作。否则它将返回null。