Export (0) Print
Expand All

HttpApplication.GetOutputCacheProviderName Method

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)

public virtual string GetOutputCacheProviderName(
	HttpContext context
)

Parameters

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.

ExceptionCondition
ProviderException

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" 
    Else 
        Return MyBase.GetOutputCacheProviderName(context) 
    End If 
End Sub
public override string GetOutputCacheProviderName(HttpContext context)
{
    if (context.Request.Path.EndsWith("Advanced.aspx"))
        return "DiskCache";
    else
        return base.GetOutputCacheProviderName(context);
}

.NET Framework

Supported in: 4.5, 4

Windows 8.1, Windows Server 2012 R2, Windows 8, Windows Server 2012, Windows 7, Windows Vista SP2, Windows Server 2008 (Server Core Role not supported), Windows Server 2008 R2 (Server Core Role supported with SP1 or later; Itanium not supported)

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.

Show:
© 2014 Microsoft