在应用程序开始或结束时清除会话 [英] clearing Session on application start or application end

查看:74
本文介绍了在应用程序开始或结束时清除会话的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

嗨!!!

我有个问题.我已经部署了一个网站.当用户进入并将产品添加到购物车时,它们将添加到我通过类文件添加的会话变量中.

Hi !!!

i have a problem. i have a deployed a website. When user enters and add product to the cart they are added to a session variable which i have added through a class file.

static ShoppingCart()
   {
       // If the cart is not in the session, create one and put it there
       // Otherwise, get it from the session
       if (HttpContext.Current.Session["ShoppingCart"] == null)
       {
           Instance = new ShoppingCart();
           Instance.Items = new List<CartItem>();
           HttpContext.Current.Session["ShoppingCart"] = Instance;
       }
       else
       {
           Instance = (ShoppingCart)HttpContext.Current.Session["ShoppingCart"];
       }
   }




现在,如果用户关闭该网站,而另一个用户打开该网站,则我的购物车显示的是前一个用户添加的对象.

如何清除应用程序开始或应用程序结束时的购物车商品?
访问 www.woodworld.co




now if user closes the website an another user open the website, my cart is showing the objects added by the previous user.

how to clear the cart items on application start or application end ???
Visit www.woodworld.co

推荐答案

您好,
我希望你有Globlel.asax文件.
在该文件中的
Hi,
i wish you have Globlel.asax file.
In that file
Session_OnEnd

方法.
如果您退出网站

method.
if you log out from the site

Session_OnEnd

,并使用

Session.Abandon(); 

方法.
但是,如果您关闭浏览器,它将不会启动,并使用以下文章来解决该问题.

"target =" _ blank"title ="新窗口> ^ ]

http://zeeshanumardotnet.blogspot.com/2011/01/how-to-end-session-when-browser-is.html [ http://forums.asp.net/t/1116238.aspx/2/10 [ ^ ]

如果对您有帮助,请立即将其标记为答案.

method.
But if you close the browser it will not fired and use following articles to solve that problem.

http://aspalliance.com/1294_CodeSnip_Handle_Browser_Close_Event_on_the_ServerSide.all[^]

http://zeeshanumardotnet.blogspot.com/2011/01/how-to-end-session-when-browser-is.html[^]

http://forums.asp.net/t/1116238.aspx/2/10[^]

do not hesitate to mark this as answer if this helps to you..


用于清除会话数据请使用
For Clearing Session Data use
Session.Abondon();
Session.Clear();


会话是用户特定对象.如果您在Session中存储了数据,则该数据仅适用于该终端的那个特定用户.


Session is a user specefic object. If you stored a data in Session then the data is only for the that particular user of that terminal.


这篇关于在应用程序开始或结束时清除会话的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆