ISessionIDManager.GetSessionID(HttpContext) Yöntem

Tanım

Oturum tanımlayıcısını geçerli HTTP isteğinin bağlamından alır.

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

Parametreler

context
HttpContext

HTTP isteklerini işlemek için kullanılan sunucu nesnelerine başvuran geçerli HttpContext nesne (örneğin, Request ve Response özellikleri).

Döndürülenler

HTTP isteğiyle gönderilen geçerli oturum tanımlayıcısı.

Örnekler

Aşağıdaki kod örneği kısmen uygulanan GetSessionID bir yöntemi gösterir. Özel oturum kimliği yöneticiniz tanımlama bilgisi olmayan oturum tanımlayıcılarını destekliyorsa, URL'de oturum tanımlayıcıları göndermek ve almak için ISAPI filtresi gibi bir çözüm uygulamanız gerekir.

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

Açıklamalar

GetSessionID yöntemi, ve SessionStateModule olayları sırasında tarafından HttpApplication.AcquireRequestState çağrılırHttpApplication.EndRequest. HTTP isteğinden geçerli bir oturum tanımlayıcısı alamıyorsanız döndürebilirsiniz null. SessionStateModule yönteminden null alırsaGetSessionID, yeni bir oturum için yeni bir oturum tanımlayıcısı almak için yöntemini çağırırCreateSessionID.

Uygulamanız tarafından CreateSessionID döndürülen değerin HTTP yanıtında veya isteğinde geçerli olmayan karakterler içermesi mümkünse yöntemini kullanarak yöntem uygulamanızdaki oturum tanımlayıcısı değerini kodlamanız ve UrlEncode yöntem uygulamanızda SaveSessionIDUrlDecode oturum tanımlayıcısı değerinin kodunu çözme yöntemini kullanmanız GetSessionID gerekir.

Şunlara uygulanır

Ayrıca bkz.