Losing session data in ASP.NET

By default Response.Redirect terminates thread execution and there might be a race conditions in setting session variables. It is described in article Don't redirect after setting a Session variable (or do it right), so try to use another, less violent version:

Response.Redirect("cpanel.aspx", false);

如果需要troubleshooting的话,可以打印HttpContext.Current.Session.SessionID来验证

SRE实战 互联网时代守护先锋,助力企业售后服务体系运筹帷幄!一键直达领取阿里云限量特价优惠。

 

另外如果代码中,重置了session的话。也会导致session中的数据丢失

 Response.Cookies.Add(new HttpCookie("ASP.NET_SessionId", string.Empty));

扫码关注我们
微信号:SRE实战
拒绝背锅 运筹帷幄