HttpCachePolicy.AddValidationCallback Method
Registers a validation callback for the current response.
[Visual Basic] Public Sub AddValidationCallback( _ ByVal handler As HttpCacheValidateHandler, _ ByVal data As Object _ ) [C#] public void AddValidationCallback( HttpCacheValidateHandler handler, object data ); [C++] public: void AddValidationCallback( HttpCacheValidateHandler* handler, Object* data ); [JScript] public function AddValidationCallback( handler : HttpCacheValidateHandler, data : Object );
Parameters
- handler
- The HttpCacheValidateHandler value.
- data
- The arbitrary user-supplied data that is passed back to the AddValidationCallback delegate.
Exceptions
| Exception Type | Condition |
|---|---|
| ArgumentNullException | handler is a null reference (Nothing in Visual Basic). |
Remarks
AddValidationCallback provides a mechanism to programmatically check the validity of a item in the cache before the item is returned from the cache.
Before the response is served from the Web server cache, all registered handlers are queried to ensure resource validity. If any handler sets a flag indicating that the resource is invalid, the entry is marked invalid and evicted from the cache. The request is then handled as if it were a cache miss.
Example
[Visual Basic] <%@ Page Language="VB" %> <%@ OutputCache VaryByParam="none" Duration=600 %> <Script runat="server"> shared validationstate As String Public Sub Page_Load(sender As Object, e As EventArgs) Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(AddressOf Me.Validate), nothing) stamp.InnerHtml = DateTime.Now.ToString("r") End Sub Public Sub Validate(context As HttpContext, data As Object, ByRef status as HttpValidationStatus) If (context.Request.QueryString("Valid") = "false") Then status = HttpValidationStatus.Invalid Elseif (context.Request.QueryString("Valid") = "ignore") Then status = HttpValidationStatus.IgnoreThisRequest Else status = HttpValidationStatus.Valid End If End Sub </Script> [C#] <%@ OutputCache VaryByParam="none" Duration=600 %> <Script Language="C#" runat="server"> static string validationstate; public void Page_Load() { Response.Cache.AddValidationCallback(new HttpCacheValidateHandler(Validate), null); stamp.InnerHtml = DateTime.Now.ToString("r"); } public void Validate(HttpContext context, Object data, ref HttpValidationStatus status) { if (context.Request.QueryString["Valid"] == "false") { status = HttpValidationStatus.Invalid; } else if (context.Request.QueryString["Valid"] == "ignore") { status = HttpValidationStatus.IgnoreThisRequest; } else { status = HttpValidationStatus.Valid; } } </Script>
[C++, JScript] No example is available for C++ or JScript. To view a Visual Basic or C# example, click the Language Filter button
in the upper-left corner of the page.
Requirements
Platforms: Windows 2000, Windows XP Professional, Windows Server 2003 family
See Also
HttpCachePolicy Class | HttpCachePolicy Members | System.Web Namespace