我正在使用的系統不使用標準ASP.NET身份驗證/成員資格設施來記錄用戶輸入/輸出。因此,在登錄用戶之後,我想向用戶發出新的會話ID以防止會話陷入/劫持。我遇到的問題是,儘管我已經能夠使用新ID成功創建新會話,並將各種組件複製到新創建的會話中,例如。會話[ 「值」]。在新創建的會話下面的代碼片段的末尾是當前的HTTPContext會話,並具有經過複製的會話值。但是,在執行Response.Redirect之後,新會話正在執行,但是兩個請求中都沒有會話[「值」]持續存在。正如你可以從下面的代碼中看到的,我試圖將這些值添加到許多集合中以利用。新創建的會話不會保留會話內容
任何幫助將是驚人的!在此先感謝
bool IsAdded = false;
bool IsRedirect = false;
HttpSessionState state = HttpContext.Current.Session;
SessionIDManager manager = new SessionIDManager();
HttpStaticObjectsCollection staticObjects = SessionStateUtility.GetSessionStaticObjects(HttpContext.Current);
SessionStateItemCollection items = new SessionStateItemCollection();
foreach (string item in HttpContext.Current.Session.Contents)
{
var a = HttpContext.Current.Session.Contents[item];
items[item] = a;
}
HttpSessionStateContainer newSession = new HttpSessionStateContainer(
manager.CreateSessionID(HttpContext.Current),
items,
staticObjects,
state.Timeout,
true,
state.CookieMode,
state.Mode,
state.IsReadOnly);
foreach (string item in HttpContext.Current.Session.Contents)
{
var a = HttpContext.Current.Session.Contents[item];
newSession.Add(item,a);
}
SessionStateUtility.RemoveHttpSessionStateFromContext(HttpContext.Current);
SessionStateUtility.AddHttpSessionStateToContext(HttpContext.Current, newSession);
manager.RemoveSessionID(HttpContext.Current);
manager.SaveSessionID(HttpContext.Current, newSession.SessionID, out IsRedirect, out IsAdded);
return newSession.SessionID;
不,因爲它是一個新的會話(即在此請求期間創建的)添加到會話中的任何值在我做Response.redirect(頁面,false) – MiiisterJim