SessionIDManager.Validate(String) メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
セッション識別子が有効かどうかを示す値を取得します。
public:
virtual bool Validate(System::String ^ id);
public virtual bool Validate(string id);
abstract member Validate : string -> bool
override this.Validate : string -> bool
Public Overridable Function Validate (id As String) As Boolean
パラメーター
- id
- String
検証するセッション識別子。
返品
true セッション識別子が有効な場合。それ以外の場合は false。
実装
例
次のコード例は、SessionIDManager クラスを継承し、CreateSessionIDとしてValidateを指定して検証するメソッドでGuidメソッドとSessionID メソッドをオーバーライドするクラスを示しています。
using System;
using System.Configuration;
using System.Web.Configuration;
using System.Web;
using System.Web.SessionState;
namespace Samples.AspNet.Session
{
public class GuidSessionIDManager : SessionIDManager
{
public override string CreateSessionID(HttpContext context)
{
return Guid.NewGuid().ToString();
}
public override bool Validate(string id)
{
try
{
Guid testGuid = new Guid(id);
if (id == testGuid.ToString())
return true;
}
catch
{
}
return false;
}
}
}
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Web
Imports System.Web.SessionState
Namespace Samples.AspNet.Session
Public Class GuidSessionIDManager
Inherits SessionIDManager
Public Overrides Function CreateSessionID(context As HttpContext) As String
Return Guid.NewGuid().ToString()
End Function
Public Overrides Function Validate(id As String) As Boolean
Try
Dim testGuid As Guid = New Guid(id)
If id = testGuid.ToString() Then _
Return True
Catch
End Try
Return False
End Function
End Class
End Namespace
この例で示すカスタム クラスを使用するには、次の例に示すように、Web.config ファイル内の SessionID HTTP モジュールをカスタム クラスに置き換えます。
<httpModules>
<remove name="SessionID" />
<add name="SessionID"
type="Samples.AspNet.Session.GuidSessionIDManager" />
</httpModules>
注釈
このメソッドは、アプリケーション コードから呼び出されるものではありません。
Validateメソッドは、指定されたidが、a から z までの小文字と 0 から 5 までの数字で構成される 24 文字の文字列であり、セッション ID の最大長が 80 文字を超えていないことを確認します。
GetSessionID メソッドは、HTTP 要求からセッション識別子を取得するときにValidate メソッドを呼び出して、指定されたセッション識別子が適切に書式設定されていることを確認します。
注意 (継承者)
SessionIDManager クラスを継承するクラスを作成し、独自のカスタム実装で CreateSessionID(HttpContext) メソッドと Validate(String) メソッドをオーバーライドすることで、セッション状態 ASP.NET 使用するカスタム セッション識別子を指定できます。 カスタム セッション識別子を作成する場合でも、セッション ID は SessionIDManager クラスによって 80 文字に制限されます。