2016-04-19 20 views
2

私はcookielessセッションをASP.NET WebForms 4.0アプリケーションで使用しています。ASP.NET WebForms - 現在のHttpContextで新しいセッションを作成して使用する

私のprojectIDパラメータが変更されたときなど、PostBackの間に新しいセッションを作成して新しいセッションにデータを保存することはできますか?

// Example url with session-1: http://localhost:12345/(S(session-1))/page1.aspx?projectID=2 

protected void Page_Load(object sender, EventArgs e) 
{ 
    string projectID = Request.Params["projectID"]; 

    // When projectID parameter was changed since last request, create a new session for e.g. "Project 2" 
    if (Session["ProjectID"] != projectID) 
    { 
     // Create new session (e.g. session-2) and use it as of now in current HttpContext 
    } 

    // Save projectID in session-2 instead of in session-1 
    Session["ProjectID"] = projectID; 

答えて

1

SessionIDManagerを試してください。

System.Web.SessionState.SessionIDManager manager = new System.Web.SessionState.SessionIDManager(); 
        string newCaller = manager.CreateSessionID(HttpContext.Current); 
        bool isAdded = false; 
        bool isRedirect = false; 
        manager.SaveSessionID(HttpContext.Current, newCaller, out isRedirect, out isAdded); 
        SessionID = newCaller; 
+0

ご回答ありがとうございます。残念ながら、プロパティ "SessionID"(読み取り専用のSession.SessionIDのみ)はありません。おそらく、新しいHttpSessionStateオブジェクトを作成し、それをSession-Propertyに割り当てる必要があります。しかしどうですか? –

+0

SessionIDは新しいセッションIDを知るためのローカル変数にすぎません – fdfey

関連する問題