SessionIDManager.CreateSessionID(HttpContext) 메서드

정의

세션에 대한 고유한 세션 식별자를 만듭니다.

public:
 virtual System::String ^ CreateSessionID(System::Web::HttpContext ^ context);
public virtual string CreateSessionID(System.Web.HttpContext context);
abstract member CreateSessionID : System.Web.HttpContext -> string
override this.CreateSessionID : System.Web.HttpContext -> string
Public Overridable Function CreateSessionID (context As HttpContext) As String

매개 변수

context
HttpContext

HTTP 요청을 처리하는 데 사용되는 서버 개체(예: 및 HttpContext 속성)를 참조하는 Request 현재 Response 개체입니다.

반품

고유한 세션 식별자입니다.

구현

예제

다음 코드 예제에서는 클래스를 SessionIDManager 상속 하 고 제공 하 고 로 유효성을 검사 하는 메서드와 CreateSessionID 메서드를 재정 ValidateGuid하는 클래스를 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

이 예제에 설명된 사용자 지정 클래스를 사용하려면 다음 예제와 같이 sessionState 요소(ASP.NET Settings Schema) 요소의 sessionIDManagerType 특성을 구성합니다.

<sessionState
  Mode="InProc"
  stateConnectionString="tcp=127.0.0.1:42424"
  stateNetworkTimeout="10"
  sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI"
  sqlCommandTimeout="30"
  customProvider=""
  cookieless="false"
  regenerateExpiredSessionId="false"
  timeout="20"
  sessionIDManagerType="Your.ID.Manager.Type,
    CustomAssemblyNameInBinFolder"
/>

설명

이 메서드는 애플리케이션 코드에서 호출할 수 없습니다.

메서드는 CreateSessionID 0에서 5 사이의 숫자와 소문자로 구성된 24자 문자열로 인코딩된 임의로 생성된 숫자인 고유 세션 식별자를 반환합니다.

상속자 참고

SessionIDManager 클래스를 상속하는 클래스를 만들고 고유한 사용자 지정 구현을 사용하여 CreateSessionID(HttpContext)Validate(String) 메서드를 재정의하여 ASP.NET 세션 상태에서 사용할 사용자 지정 세션 식별자를 제공할 수 있습니다. 사용자 지정 세션 ID가 메서드의 Validate(String) 기본 구현에 의해 적용되는 문자 제약 조건을 충족하지 않는 경우 사용자 지정 세션 식별자의 유효성 검사를 제공하도록 메서드를 재정 Validate(String) 의해야 합니다. 이 경우 SessionIDManager 클래스는 사용자 지정 세션 식별자가 HTTP 응답에서 인코딩된 URL과 각각 및 Encode(String) 메서드를 사용하여 Decode(String) HTTP 요청에서 디코딩된 URL인지 확인합니다.

적용 대상

추가 정보