HttpCacheValidateHandler 委托

定义

表示一个方法,在从缓存提供某个缓存项之前将调用该方法来验证该项。

public delegate void HttpCacheValidateHandler(HttpContext ^ context, System::Object ^ data, HttpValidationStatus % validationStatus);
public delegate void HttpCacheValidateHandler(HttpContext context, object data, ref HttpValidationStatus validationStatus);
type HttpCacheValidateHandler = delegate of HttpContext * obj * HttpValidationStatus -> unit
Public Delegate Sub HttpCacheValidateHandler(context As HttpContext, data As Object, ByRef validationStatus As HttpValidationStatus)

参数

context
HttpContext

包含有关当前请求的信息的 HttpContext 对象。

data
Object

用于验证缓存项的用户提供的数据。

validationStatus
HttpValidationStatus

一个 HttpValidationStatus 枚举值。 委托应设置该值来指示验证的结果。

示例

下面的代码示例演示如何向应用程序添加新的缓存验证委托。


private void Page_Load(Object sender, EventArgs e)
{
   Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(CacheValidate1), null);
}

public void CacheValidate1(HttpContext context, Object data, ref HttpValidationStatus status) 
{
   if (context.Request.QueryString["Valid"] == "false") 
   {
      status = HttpValidationStatus.Invalid;
   }
   else 
   {
      status = HttpValidationStatus.Valid;
   }
}

Private Sub Page_Load(sender As Object, e As EventArgs)
   Response.Cache.AddValidationCallback(New HttpCacheValidateHandler(AddressOf CacheValidate1), Nothing)
End Sub
   
Public Sub CacheValidate1(context As HttpContext, data As Object, ByRef status As HttpValidationStatus)
   If context.Request.QueryString("Valid") = "false" Then
      status = HttpValidationStatus.Invalid
   Else
      status = HttpValidationStatus.Valid
   End If
End Sub

注解

如果缓存项在方法范围内 HttpCacheValidateHandler 失效,则会从缓存中逐出该项,并且该项的请求被视为缓存未命中。

扩展方法

GetMethodInfo(Delegate)

获取指示指定委托表示的方法的对象。

适用于

另请参阅