共用方式為


ISessionIDManager.Validate(String) 方法

定義

確認提供的工作階段識別項是有效的。

public:
 bool Validate(System::String ^ id);
public bool Validate (string id);
abstract member Validate : string -> bool
Public Function Validate (id As String) As Boolean

參數

id
String

要驗證的工作階段識別項。

傳回

如果工作階段識別項有效,則為 true,否則為 false

範例

下列程式碼範例會實作 Validate 方法,並確保會話識別碼值是有效的 Guid

public bool Validate(string id)
{
  try
  {
    Guid testGuid = new Guid(id);

    if (id == testGuid.ToString())
      return true;
  }
  catch
  {
  }

  return false;
}
Public Function Validate(id As String) As Boolean _
  Implements ISessionIDManager.Validate

  Try
    Dim testGuid As Guid = New Guid(id)

    If id = testGuid.ToString() Then _
      Return True
  Catch
  
  End Try

  Return False
End Function

備註

方法 Validate 會驗證提供的 id 是有效的會話識別碼。

從 HTTP 要求擷取會話識別碼時,您的 ISessionIDManager 實作應該從 GetSessionID 方法呼叫 Validate 方法,以確保提供的會話識別碼格式正確。

適用於

另請參閱