Search code examples
asp.netc#-4.0shopping-cart

Shopping cart session specific to instance


Strange - Session - Inproc - mode use cookies name asp_net session id, timeout 20 , is shared across clients, not sure !!! session should be unique for each client, but its been shared across clients !!

In my asp.net application, the shopping cart session has been shared across the requests, not sure how happened,it should be different specific to the request , each request in IIS should have each session, but all the requests in IIS is been shared by this session`public class PODCart {

#region Properties

public List<PODCartItem> Items { get; private set; }

#endregion

#region Singleton Implementation

public static readonly PODCart Instance;

static PODCart()
{
    if (HttpContext.Current.Session["C"] == null)
    {
        Instance = new PODCart();
        Instance.Items = new List<PODCartItem>();
        HttpContext.Current.Session["C"] = Instance;
    }
    else
        Instance = (PODCart)HttpContext.Current.Session["C"];
}

protected PODCart() { }

}`

Really need to know the fix as quick as possible, though the singleton implementation is done.


Solution

  • You have a singleton class defined and you are assigning it to every single session. Of course it's going to use the same one.

    It really looks like PODCart shouldn't be a singleton.