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]
<Serializable>
Public Delegate Sub HttpCacheValidateHandler( _
   ByVal context As HttpContext, _
   ByVal data As Object, _
   ByRef validationStatus As HttpValidationStatus _
)
[C#]
[Serializable]
public delegate void HttpCacheValidateHandler(
   HttpContext context,
   object data,
   ref HttpValidationStatus validationStatus
);
[C++]
[Serializable]
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.

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

Remarks

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

Example

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

[C#] 

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;
   }
}
    

[C++] 
private:
   void Page_Load(Object* /*sender*/, EventArgs* /*e*/)
   {
      Response->Cache->AddValidationCallback(new HttpCacheValidateHandler(this, &Page1::CacheValidate1), 0);
   }

public:
   void CacheValidate1(HttpContext* context, Object* /*data*/, HttpValidationStatus * status)
   {
      if (String::Compare(context->Request->QueryString->Item[S"Valid"], S"false") == 0)
         *status = HttpValidationStatus::Invalid;
      else
         *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.

Requirements

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

Show:
© 2014 Microsoft