SessionIDManager.Validate(String) 메서드

정의

세션 식별자가 유효한지 여부를 나타내는 값을 가져옵니다.

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 메서드를 재정 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

이 예제에 설명된 사용자 지정 클래스를 사용하려면 다음 예제와 같이 Web.config 파일의 HTTP 모듈을 사용자 지정 클래스로 바꿉 SessionID 다.

<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자로 제한됩니다.

적용 대상

추가 정보