Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Export (0) Print
Expand All

HttpCacheValidateHandler Delegate

Delegate method that is called when a cached item is validated. Cache items invalidated within the method are treated as cache misses.

[Visual Basic]
Public Delegate Sub HttpCacheValidateHandler( _
   ByVal context As HttpContext, _
   ByVal data As Object, _
   ByRef validationStatus As HttpValidationStatus _
public delegate void HttpCacheValidateHandler(
   HttpContext context,
   object data,
   ref HttpValidationStatus validationStatus
public __gc __delegate void HttpCacheValidateHandler(
   HttpContext* context,
   Object* data,
   HttpValidationStatus* validationStatus

[JScript] In JScript, you can use the delegates in the .NET Framework, but you cannot define your own.

Parameters [Visual Basic, C#, C++]

The declaration of your callback method must have the same parameters as the HttpCacheValidateHandler delegate declaration.

The HttpContext object containing information about the current request.
User-supplied data used to validate the cached item.
An HttpValidationStatus enumeration value. Your delegate should set this value to indicate the result of the validation.


If any handler invalidates the cached item, the item is evicted from the cache and the request is handled as a cache miss.


[Visual Basic, C#, C++] The following example adds a new cache validation delegate to an aplication.

[Visual Basic] 

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
      status = HttpValidationStatus.Valid
   End If
End Sub


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;
      status = HttpValidationStatus.Valid;

   void Page_Load(Object* /*sender*/, EventArgs* /*e*/)
      Response->Cache->AddValidationCallback(new HttpCacheValidateHandler(this, &Page1::CacheValidate1), 0);

   void CacheValidate1(HttpContext* context, Object* /*data*/, HttpValidationStatus * status)
      if (String::Compare(context->Request->QueryString->Item[S"Valid"], S"false") == 0)
         *status = HttpValidationStatus::Invalid;
         *status = HttpValidationStatus::Valid;

[JScript] No example is available for JScript. To view a Visual Basic, C#, or C++ example, click the Language Filter button Language Filter in the upper-left corner of the page.


Namespace: System.Web

Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family

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

See Also

System.Web Namespace

© 2015 Microsoft