c# - 奇怪的 session 问题

标签 c# asp.net

我的 session 类中有这个字段:

public bool IsCartRecentlyUpdated
{
    get
    {
        if (this.session["IsCartRecentlyUpdated"] != null)
        {
            return (bool)this.session["IsCartRecentlyUpdated"];
        }
        else
        {
            this.session["IsCartRecentlyUpdated"] = false;
            return (bool)this.session["IsCartRecentlyUpdated"];
        }
    }
    set
    {
        this.session["IsCartRecentlyUpdated"] = value;
    }
}

每当用户将产品添加到购物车时,我都会将此值设置为 true:

  public void AddToCart(Product product, int quantity)
    {
        IsCartRecentlyUpdated = true;
     //other code for updating the cart
     }

将产品添加到购物车会进行回发,因此我可以在购物车所在的通用母版页的 Page_Load 中显示消息(例如:产品已成功添加)位于,当产品刚刚添加到购物车时:

 protected void Page_Load(object sender, EventArgs e)
{
    if (this.sessionsUtil.IsCartRecentlyUpdated)
    {
        this.lblCartWarning.Text = (string)GetLocalResourceObject("CartWarning");
        imgCardLogos.Visible = false;
    }
    else
    {
        this.lblCartWarning.Text = String.Empty;
        imgCardLogos.Visible = true;
    }
//other code
//put it back to false to not show the message each time the page is loaded
this.sessionsUtil.IsCartRecentlyUpdated = false;
}

好吧,这段代码本地很好地工作,但是在服务器上,它在添加产品添加到购物车但在第二页加载... (我猜想在服务器上以某种方式在更新 session 变量之前加载页面 - 非常奇怪)

你知道为什么吗?我没有在代码中看到任何问题...

最佳答案

像这样的奇怪问题使用 IIS express 可能更容易解决 http://weblogs.asp.net/scottgu/archive/2011/01/03/vs-2010-sp1-beta-and-iis-developer-express.aspx

关于c# - 奇怪的 session 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4547747/

相关文章:

c# - 影响所有 asp.net 控件的虚拟应用程序根的 URL 重写

asp.net - 谷歌的字符编码是什么?

asp.net - 如何显示特色产品主页 - NopCommerce?

c# - 我正在尝试在 asp.net c# 中使用 google API 发送电子邮件并收到错误 400 redirect_uri_mismatch

ASP.NET 如何在提交时禁用按钮?

c# - DbSet<TEntity>.Find() - 反射

C# 即使具有管理员权限也无法访问系统文件

c# - : Conversion operators cannot convert from an interface type如何解决

c# - 我无法截屏

c# - XSD2Code 类需要包含元素集合的重名元素