ISessionIDManager.SaveSessionID(HttpContext, String, Boolean, Boolean) 方法

定義

將新建立的工作階段識別項儲存至 HTTP 回應。

public:
 void SaveSessionID(System::Web::HttpContext ^ context, System::String ^ id, [Runtime::InteropServices::Out] bool % redirected, [Runtime::InteropServices::Out] bool % cookieAdded);
public void SaveSessionID (System.Web.HttpContext context, string id, out bool redirected, out bool cookieAdded);
abstract member SaveSessionID : System.Web.HttpContext * string * bool * bool -> unit
Public Sub SaveSessionID (context As HttpContext, id As String, ByRef redirected As Boolean, ByRef cookieAdded As Boolean)

參數

context
HttpContext

目前的 HttpContext 物件,參考用於處理 HTTP 要求 (例如,RequestResponse 屬性) 的伺服器物件。

id
String

工作階段識別項。

redirected
Boolean

這個方法傳回時,其中會包含布林值,如果回應會重新導向至目前的 URL,且會將工作階段識別項加入 URL,則該值為 true,否則為 false

cookieAdded
Boolean

這個方法傳回時,其中會包含布林值,如果已將 Cookie 加入 HTTP 回應,則該值為 true,否則為 false

範例

下列程式碼範例顯示部分實 SaveSessionID 作的方法。 如果您的自訂會話識別碼管理員支援無 Cookie 會話識別碼,您必須實作解決方案,以在 URL 中傳送和擷取會話識別碼,例如 ISAPI 篩選準則。

public void SaveSessionID(HttpContext context, string id, out bool redirected, out bool cookieAdded)
{
  redirected = false;
  cookieAdded = false;

  if (pConfig.Cookieless == HttpCookieMode.UseUri)
  {
    // Add the SessionID to the URI. Set the redirected variable as appropriate.

    redirected = true;
    return;
  }
  else
  {
    context.Response.Cookies.Add(new HttpCookie(pConfig.CookieName, id));
    cookieAdded = true;
  }
}
Public Sub SaveSessionID(context As HttpContext, _
                         id As String, _
                         ByRef redirected As Boolean, _
                         ByRef cookieAdded As Boolean) _
  Implements ISessionIDManager.SaveSessionID

  redirected = False
  cookieAdded = False

  If pConfig.Cookieless = HttpCookieMode.UseUri Then

    ' Add the SessionID to the URI. Set the redirected variable as appropriate.

    redirected = True
    Return
  Else
    context.Response.Cookies.Add(New HttpCookie(pConfig.CookieName, id))
    cookieAdded = True
  End If
End Sub

備註

方法 SaveSessionID 會在 事件期間 HttpApplication.AcquireRequestStateSessionStateModule 物件呼叫。 方法 SaveSessionID 會在使用無 Cookie 會話狀態) 或非過期會話 Cookie 時,將會話識別碼儲存在 URL (。

如果從實 CreateSessionID 作傳回的值可能包含在 HTTP 回應或要求中不正確字元,您應該使用 UrlEncode 方法來編碼方法實作中的 SaveSessionID 會話識別碼值,以及 UrlDecode 將方法實作中的 GetSessionID 會話識別碼值解碼的方法。

適用於

另請參閱