Aracılığıyla paylaş


ISessionIDManager.GetSessionID(HttpContext) Yöntem

Tanım

Geçerli HTTP isteğinin bağlamından oturum tanımlayıcısını 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'deki oturum tanımlayıcılarını 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 HttpApplication.EndRequest olayları sırasında tarafından SessionStateModule çağrılırHttpApplication.AcquireRequestState. HTTP isteğinden geçerli bir oturum tanımlayıcısı alamıyorsanız döndürebilirsiniz null. SessionStateModule yönteminden GetSessionID alırsanull, 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 bir HTTP yanıtı 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 ve UrlDecode yöntem uygulamanızdaki SaveSessionIDGetSessionID oturum tanımlayıcısı değerinin kodunu çözme yöntemini kullanmanız UrlEncode gerekir.

Şunlara uygulanır

Ayrıca bkz.