Is it possible to cache a page by Browser Version and/or some params

Platform: ASP.NET| Category: Output Caching

Yes. In your page:


<%@ OutputCache Duration='60' VaryByParams='abc;xyz' VaryByCustom='browsermajorversion' %> 

In your global.asax file:

VB.NET


Public Overrides Function GetVaryByCustomString(context As HttpContext, custom As String) As String
	If custom.ToLower() = 'browsermajorversion' Then
		Dim browser As HttpBrowserCapabilities = context.Request.Browser
			Return browser.Browser + ' ' + browser.MajorVersion
	Else
		Return MyBase.GetVaryByCustomString(context, custom)
	End If
End Function ’GetVaryByCustomString

C#


public override string GetVaryByCustomString(HttpContext context, string custom)
{ 
	if (custom.ToLower() == 'browsermajorversion') { 
		HttpBrowserCapabilities browser = context.Request.Browser; 
		return browser.Browser + ' ' + browser.MajorVersion; 
	} 
	else 
	{ 
	return base.GetVaryByCustomString(context, custom); 
	} 
} 

Share with

Related FAQs

Couldn't find the FAQs you're looking for?

Please submit your question and answer.