ISessionIDManagerとは? わかりやすく解説

ISessionIDManager インターフェイス

メモ : このインターフェイスは、.NET Framework version 2.0新しく追加されたものです。

カスタムセッション状態識別子マネージャ実装する必要があるコントラクト定義します

名前空間: System.Web.SessionState
アセンブリ: System.Web (system.web.dll 内)
構文構文

Public Interface ISessionIDManager
Dim instance As ISessionIDManager
public interface ISessionIDManager
public interface class ISessionIDManager
public interface ISessionIDManager
public interface ISessionIDManager
解説解説

ISessionIDManager インターフェイスは、セッション識別子値のためのカスタム マネージャ作成するために実装する必要があるメソッド指定しますISessionIDManager インターフェイス実装は、セッション識別子値を作成して検証しHTTP 要求からのセッション識別子値の取得および HTTP 応答へのセッション識別子保存管理しますカスタム セッション ID マネージャは、sessionState 要素 (ASP.NET 設定スキーマ) 構成要素sessionIDManagerType 属性使用して有効にます。

ISessionIDManager インターフェイス実装Cookie なしのセッション識別子サポートする場合ISAPI フィルタなどのセッション識別子URL含めてやり取りするソリューション実装する必要があります

ASP.NET セッション状態使用するカスタムセッション識別子値のみを提供する場合は、SessionIDManager クラス継承するクラス作成し、CreateSessionID メソッドValidate メソッドのみを各自カスタム実装オーバーライドます。これによって、SessionIDManager 基本クラス使用して HTTP 応答に値を保存しHTTP 要求から値を取得しながら、独自のセッション識別子値を提供できますSessionIDManager クラスオーバーライドし、これらのメソッド実装する例については、SessionIDManager クラスCreateSessionID メソッドの例を参照してください

使用例使用例

Cookie ベースセッション ID マネージャ実装するクラスコード例次に示します

Imports System
Imports System.Configuration
Imports System.Web.Configuration
Imports System.Web
Imports System.Web.SessionState


Namespace Samples.AspNet.Session


  Public Class MySessionIDManager
    Implements IHttpModule, ISessionIDManager

    Private pConfig As SessionStateSection
 = Nothing

    '
    ' IHttpModule Members
    '

    '
    ' IHttpModule.Init
    '

    Public Sub Init(app As
 HttpApplication) Implements IHttpModule.Init
    
      ' Obtain session-state configuration settings.

      If pConfig Is Nothing
 Then      
        Dim cfg As System.Configuration.Configuration
 = _
          WebConfigurationManager.OpenWebConfiguration( _
            System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath)
        pConfig = CType(cfg.GetSection("system.web/sessionState"),
 SessionStateSection)
      End If

    End Sub


    '
    ' IHttpModule.Dispose
    '

    Public Sub Dispose() Implements
 IHttpModule.Dispose
    
    End Sub



    '
    ' ISessionIDManager.Initialize
    '

    Public Sub Initialize() Implements
 ISessionIDManager.Initialize

    End Sub


    '
    ' ISessionIDManager.InitializeRequest
    '

    Public Function InitializeRequest(context
 As HttpContext,  _
                                      suppressAutoDetectRedirect As
 Boolean,  _
                                      ByRef supportSessionIDReissue
 As Boolean) As Boolean
 _
                                      Implements ISessionIDManager.InitializeRequest

      If pConfig.Cookieless = HttpCookieMode.UseCookies Then
        supportSessionIDReissue = False
        Return False
      Else
        supportSessionIDReissue = True
        Return context.Response.IsRequestBeingRedirected
      End If
    End Function



    '
    ' ISessionIDManager Members
    '


    '
    ' ISessionIDManager.GetSessionID
    '
    Public Function GetSessionID(context As
 HttpContext) As String _
      Implements ISessionIDManager.GetSessionID
    
      Dim id As String =
 Nothing

      If pConfig.Cookieless = HttpCookieMode.UseUri Then
        ' Retrieve the SessionID from the URI.
      Else
        id = context.Request.Cookies(pConfig.CookieName).Value
      End If    

      ' Verify that the retrieved SessionID is valid. If not, return
 Nothing.

      If Not Validate(id) Then
 _
        id = Nothing

      Return id
    End Function

    '
    ' ISessionIDManager.CreateSessionID
    '

    Public Function CreateSessionID(context
 As HttpContext) As String
 _
      Implements ISessionIDManager.CreateSessionID
    
      Return Guid.NewGuid().ToString()
    End Function

    '
    ' ISessionIDManager.RemoveSessionID
    '

    Public Sub RemoveSessionID(context As
 HttpContext) _
      Implements ISessionIDManager.RemoveSessionID

      context.Response.Cookies.Remove(pConfig.CookieName)

    End Sub


    '
    ' ISessionIDManager.SaveSessionID
    '

    Public Sub SaveSessionID(context As
 HttpContext, _
                             id As String,
 _
                             ByRef redirected As
 Boolean, _
                             ByRef cookieAdded As
 Boolean) _
      Implements ISessionIDManager.SaveSessionID
    
      redirected = False
      cookieAdded = False

      If pConfig.Cookieless = HttpCookieMode.UseUri Then

        ' Add the SessionID to the URI. Set the redirected variable
 as appropriate.

        redirected = True
        Return
      Else
        context.Response.Cookies.Add(New HttpCookie(pConfig.CookieName,
 id))
        cookieAdded = True
      End If
    End Sub


    '
    ' ISessionIDManager.Validate
    '

    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

  End Class
End Namespace
using System;
using System.Configuration;
using System.Web.Configuration;
using System.Web;
using System.Web.SessionState;


namespace Samples.AspNet.Session
{

  public class MySessionIDManager : IHttpModule,
 ISessionIDManager
  {

    private SessionStateSection pConfig = null;


    //
    // IHttpModule Members
    //


    //
    // IHttpModule.Init
    //

    public void Init(HttpApplication app)
    {
      // Obtain session-state configuration settings.

      if (pConfig == null)
      {
        Configuration cfg =
          WebConfigurationManager.OpenWebConfiguration(System.Web.Hosting.HostingEnvironment.ApplicationVirtualPath);
        pConfig = (SessionStateSection)cfg.GetSection("system.web/sessionState");
      }
    }


    //
    // IHttpModule.Dispose
    //

    public void Dispose()
    {
    }




    //
    // ISessionIDManager Members
    //




    //
    // ISessionIDManager.Initialize
    //

    public void Initialize()
    {
    }


    //
    // ISessionIDManager.InitializeRequest
    //

    public bool InitializeRequest(HttpContext
 context, 
                                  bool suppressAutoDetectRedirect,
 
                                  out bool supportSessionIDReissue)
    {
      if (pConfig.Cookieless == HttpCookieMode.UseCookies)
      {
        supportSessionIDReissue = false;
        return false;
      }
      else
      {
        supportSessionIDReissue = true;
        return context.Response.IsRequestBeingRedirected;
      }
    }




    //
    // ISessionIDManager.GetSessionID
    //
    public string GetSessionID(HttpContext
 context)
    {
      string id = null;

      if (pConfig.Cookieless == HttpCookieMode.UseUri)
      {
        // Retrieve the SessionID from the URI.
      }
      else
      {
        id = context.Request.Cookies[pConfig.CookieName].Value;
      }      

      // Verify that the retrieved SessionID is valid. If not, return
 null.

      if (!Validate(id))
        id = null;

      return id;
    }

    //
    // ISessionIDManager.CreateSessionID
    //

    public string CreateSessionID(HttpContext
 context)
    {
      return Guid.NewGuid().ToString();
    }

    //
    // ISessionIDManager.RemoveSessionID
    //

    public void RemoveSessionID(HttpContext
 context)
    {
      context.Response.Cookies.Remove(pConfig.CookieName);
    }


    //
    // ISessionIDManager.SaveSessionID
    //

    public void SaveSessionID(HttpContext context,
 string id, out bool redirected, out bool
 cookieAdded)
    {
      redirected = false;
      cookieAdded = false;

      if (pConfig.Cookieless == HttpCookieMode.UseUri)
      {
        // Add the SessionID to the URI. Set the redirected variable
 as appropriate.

        redirected = true;
        return;
      }
      else
      {
        context.Response.Cookies.Add(new HttpCookie(pConfig.CookieName,
 id));
        cookieAdded = true;
      }
    }


    //
    // ISessionIDManager.Validate
    //

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

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

      return false;
    }
  }
}
.NET Framework のセキュリティ.NET Frameworkセキュリティ
プラットフォームプラットフォーム
バージョン情報バージョン情報
参照参照

ISessionIDManager メソッド


パブリック メソッドパブリック メソッド

参照参照

関連項目

ISessionIDManager インターフェイス
System.Web.SessionState 名前空間

その他の技術情報

ASP.NETセッション状態

ISessionIDManager メンバ




英和和英テキスト翻訳>> Weblio翻訳
英語⇒日本語日本語⇒英語
  

辞書ショートカット

すべての辞書の索引

「ISessionIDManager」の関連用語

ISessionIDManagerのお隣キーワード
検索ランキング

   

英語⇒日本語
日本語⇒英語
   



ISessionIDManagerのページの著作権
Weblio 辞書 情報提供元は 参加元一覧 にて確認できます。

   
日本マイクロソフト株式会社日本マイクロソフト株式会社
© 2025 Microsoft.All rights reserved.

©2025 GRAS Group, Inc.RSS