HttpApplication::GetOutputCacheProviderName Method (HttpContext^)

.NET Framework (current version)

The .NET API Reference documentation has a new home. Visit the .NET API Browser on to see the new experience.

Gets the name of the default output-cache provider that is configured for a Web site.

Namespace:   System.Web
Assembly:  System.Web (in System.Web.dll)

virtual String^ GetOutputCacheProviderName(
	HttpContext^ context


Type: System.Web::HttpContext^

An HttpContext that provides references to intrinsic server objects that are used to service HTTP requests.

Return Value

Type: System::String^

The name of the default provider.

Exception Condition

context is null or is an empty string.

You can override this method and use it to return the name of any output-cache provider that is configured for a Web site. ASP.NET retrieves a reference to the named provider and uses it to store output-cache data for the currently executing request.

By default, in ASP.NET, all HTTP responses, rendered pages, and controls use the in-memory output cache. You can change the default output-cache provider that is used for a Web application by specifying a different provider name for defaultProvider.

In addition, you can select different output-cache providers for individual control and for individual requests. The easiest way to choose a different output-cache provider for different Web user controls is to do so declaratively by using the new providerName attribute in a page or control directive, as shown in the following example:

<%@ OutputCache Duration="60" VaryByParam="None" 
    providerName="DiskCache" %>

To specify a different output cache provider for an HTTP request, you override this method in the Global.asax file to programmatically specify which provider to use for a specific request. For more information, see ASP.NET Caching Overview.

The following example shows how to programmatically specify the cache provider named DiskCache for any HTTP request that goes to the Advanced.aspx page.

[Visual Basic]

Public Overloads Overrides Sub GetOutputCacheProviderName(ByVal context _
        As HttpContext) As String 
    If context.Request.Path.EndsWith("Advanced.aspx") Then 
        Return "DiskCache" 
        Return MyBase.GetOutputCacheProviderName(context) 
    End If 
End Sub
public override string GetOutputCacheProviderName(HttpContext context)
    if (context.Request.Path.EndsWith("Advanced.aspx"))
        return "DiskCache";
        return base.GetOutputCacheProviderName(context);

.NET Framework
Available since 4.0
Return to top