将产品添加到购物车时出现问题.它被添加到所有登录的用户 [英] Problem in adding Product to cart. it is getting added to all user who login

查看:117
本文介绍了将产品添加到购物车时出现问题.它被添加到所有登录的用户的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在做电子商务网站.和Im会在母版页的public和static变量中维护所有产品和购物车数量,但是问题是,当一个用户添加任何产品时,它就会被添加到所有其他用户中

请帮助我...

I am doing eCommerce website. and Im maintaining all products and cart count in masterpage public and static variable but the problem is, when one user add any product it is getting added to all other users

Kindly help me...

推荐答案

这是因为您正在使用公共静态变量将购物车保存在内存中.

最简单的方法是将购物车商品放入会话变量或cookie中.会话/Cookie在用户之间不共享.公共静态变量是..

您应该阅读Yahya Mohammed Ammouri的这篇文章: Simple Shopping Cart(使用ASP.NET& JavaScript(浮动,可移动和可调整大小) [ ^ ]
This is because you are using public static variables to keep your cart in memory.

The easiest way for you would be to put cart items in a session variable or cookies. Session/Cookies are not shared between users. public static variables are..

You should read this article by Yahya Mohammed Ammouri : Simple Shopping Cart (Basket ) User Control using ASP.NET & JavaScript (Floating, Movable and Resizable)[^]


static变量是在类的所有instances中都相同的变量. br/>
通常,每个类都作为其自己的所有变量的副本.如果将某些声明为static,则它们在类的每个instances中将具有相同的值.

不要将其设为静态
A static variable is a variable that will be the same in all instances of a class.

Normally each class as its own copy of all variables. If you declare some as static, then they will have the same value in each instances of a class.

Don''t make it static


这篇关于将产品添加到购物车时出现问题.它被添加到所有登录的用户的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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