HttpApplication.GetOutputCacheProviderName(HttpContext) 方法


获取为网站配置的默认输出缓存提供程序的名称。Gets the name of the default output-cache provider that is configured for a Web site.

 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



一个 HttpContext,提供对服务于 HTTP 请求的内部服务器对象的引用。An HttpContext that provides references to intrinsic server objects that are used to service HTTP requests.


默认提供程序的名称。The name of the default provider.


contextnull 或是一个空字符串 ("")。context is null or is an empty string.


下面的示例演示如何以编程方式为发送到 Advanced .aspx 页的任何 HTTP 请求指定名为 DiskCache 的缓存提供程序。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";  
        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"   
        Return MyBase.GetOutputCacheProviderName(context)   
    End If   
End Sub  


您可以重写此方法,并使用它来返回为网站配置的任何输出缓存提供程序的名称。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 检索对命名提供程序的引用,并使用它来存储当前正在执行的请求的输出缓存数据。ASP.NET retrieves a reference to the named provider and uses it to store output-cache data for the currently executing request.

默认情况下,在 ASP.NET 中,所有 HTTP 响应、呈现的页和控件均使用内存中的输出缓存。By default, in ASP.NET, all HTTP responses, rendered pages, and controls use the in-memory output cache. 通过为 defaultProvider指定不同的提供程序名称,可以更改用于 Web 应用程序的默认输出缓存提供程序。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. 为不同的 Web 用户控件选择不同的输出缓存提供程序的最简单方法是使用 page 或 control 指令中的 new providerName 特性以声明方式执行此操作,如下面的示例中所示: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" %>  

若要为某个 HTTP 请求指定不同的输出缓存提供程序,请在 global.asax 文件中重写此方法,以编程方式指定要用于特定请求的提供程序。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. 有关详细信息,请参阅 ASP.NET 缓存概述For more information, see ASP.NET Caching Overview.