Edit

Share via


HttpApplication.GetOutputCacheProviderName(HttpContext) Method

Definition

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

public:
 virtual System::String ^ GetOutputCacheProviderName(System::Web::HttpContext ^ context);
public virtual string GetOutputCacheProviderName (System.Web.HttpContext context);
abstract member GetOutputCacheProviderName : System.Web.HttpContext -> string
override this.GetOutputCacheProviderName : System.Web.HttpContext -> string
Public Overridable Function GetOutputCacheProviderName (context As HttpContext) As String

Parameters

context
HttpContext

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

Returns

The name of the default provider.

Exceptions

context is null or is an empty string.

Examples

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

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

Remarks

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.

Applies to