共用方式為


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 列舉值。 您的委派 (Delegate) 應該設定這個值來指示驗證的結果。

範例

下列程式碼範例示範如何將新的快取驗證委派新增至應用程式。


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)

取得表示特定委派所代表之方法的物件。

適用於

另請參閱