跨子域的 ASP.NET MVC 会话
在我的网站中,我实现了自定义会话值。其中,登录时我将会话值设置为某个对象。该对象用于从数据库中提取用户特定数据。
现在的问题是,如果用户使用 test1.somesite.com 登录并注销并再次使用 test2.somesite.com 登录,则该用户仍在接收来自特定于 test1.somesite.com 的对象的数据。
关键是,无论哪个站点用户第一次登录第二次,如果他使用另一个子域登录,他总是会从之前的子域登录中获取数据。
从特定域注销时,我清除了所有会话(尝试了所有方法):通过放置 HttpContext.session["UserDetail"] = null;、HttpContext.Session.Abandon() 以及 HttpContext.Session.Clear();
但似乎没有任何作用
,而且我也不太了解如何跨子域处理会话变量。
我的意思是,如果我通过访问 test1.somesite.com 使用一个值初始化会话,如果在同一台计算机和同一浏览器上我也打开 test2.somesite.com,该值也将可见。
请提供任何帮助
In my website i have implemented custom session values. In which, on log on i set the session value to some object. This object is used to extract user specific data from db.
now the problem is If user logs in with : test1.somesite.com and logs off and again logs in with: test2.somesite.com that user is still receiving the data from object specific to test1.somesite.com.
the point is whichever site user first logs in with the second time if he logs in with another subdomain he is always getting the data from previous sub domain login.
on log out from specific domain i cleared all the sessions(tried everything): by putting HttpContext.session["UserDetail"] = null;, HttpContext.Session.Abandon() and also HttpContext.Session.Clear();
but nothing seems to work
and i also don't have much idea how session variables are treated across subdomains.
I mean if i initialize a session with one value by visiting test1.somesite.com will that value also be visible if on the same computer and on same browser i also open test2.somesite.com.
any help please
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
听起来像是 cookie 的问题。尝试清除会话 cookie。大致如下:
Sounds like a cookie issue. Try clearing out the session cookie. Something along the lines of:
您需要做的是将您的 asp.net 会话 ID cookie 设置为写入通配符域。
Response.Cookies("ASP.NET_SessionId").Domain = "yourdomain.com" // 或 "*.yourdomain.com"
以便 cookie 可以浮动到您的子域。
What you need to do is set your asp.net session id cookie to write to a wild card domain.
Response.Cookies("ASP.NET_SessionId").Domain = "yourdomain.com" // or "*.yourdomain.com"
So that the cookie can float to your subdomains.