开发者

Guest/Member Sessions in ASP.NET

开发者 https://www.devze.com 2023-02-23 00:28 出处:网络
Hello I have a class Cart and class ShoppingCart. Now the problem is about sessions. I have been battling with it for hours, but the issue is that the same session is being by a guest and a member. So

Hello I have a class Cart and class ShoppingCart. Now the problem is about sessions. I have been battling with it for hours, but the issue is that the same session is being by a guest and a member. So it doesnt matter if you login or not, theres just one session where the same cart exists.

My classes are below..

Class Cart
{
int ProdId;
float TotalPrice;
float UnitPrice;
int Quantity;

public Cart(int id)
{
......//initialize variables here
}
}

Class ShoppingCart{

public List<Cart>开发者_如何转开发 Items = new List<Cart>();
}

 public void AddItem(ProdId)
 {
 Cart = new Cart(ProdId)
 }
 }

How should I go about keeping a session for a member and a guest? I want to be able to keep the cart in the session, along with the Customer information. the session must change if a guest is online, and then signs in.


You could do a Session.Clear() when the user logs in?

Or instead of directly accessing the cart, have a property where you handle checking if the user is logged in or not, and if he is, destroy & re-create with the proper settings?

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号