ISessionIDManager.GetSessionID(HttpContext) 메서드

정의

현재 HTTP 요청의 컨텍스트에서 세션 식별자를 가져옵니다.

public:
 System::String ^ GetSessionID(System::Web::HttpContext ^ context);
public string GetSessionID(System.Web.HttpContext context);
abstract member GetSessionID : System.Web.HttpContext -> string
Public Function GetSessionID (context As HttpContext) As String

매개 변수

context
HttpContext

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

반품

HTTP 요청과 함께 전송된 현재 세션 식별자입니다.

예제

다음 코드 예제에서는 부분적으로 구현된 메서드를 GetSessionID 보여줍니다. 사용자 지정 세션 ID 관리자가 쿠키 없는 세션 식별자를 지원하는 경우 ISAPI 필터와 같은 URL에서 세션 식별자를 보내고 검색하기 위한 솔루션을 구현해야 합니다.

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;
}
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

설명

메서드는 GetSessionID 동안 및 SessionStateModule 이벤트에 의해 HttpApplication.AcquireRequestState 호출됩니다HttpApplication.EndRequest. HTTP 요청에서 유효한 세션 식별자를 검색할 수 없는 경우 반환 null합니다. 메서드에서 SessionStateModule 수신 null 하는 경우 메서드를 GetSessionID 호출 CreateSessionID 하여 새 세션에 대한 새 세션 식별자를 가져옵니다.

구현에서 반환된 CreateSessionID 값에 HTTP 응답 또는 요청에서 유효하지 않은 문자가 포함될 수 있는 경우 메서드를 사용하여 메서드 구현에서 세션 식별자 값을 인코딩하고 UrlEncode 메서드 구현에서 SaveSessionID 세션 식별자 값을 UrlDecode 디코딩하는 메서드를 사용해야 GetSessionID 합니다.

적용 대상

추가 정보