C# 奇怪的会话问题
我的会话类中有此字段:C# 奇怪的会话问题,c#,asp.net,C#,Asp.net,我的会话类中有此字段: public bool IsCartRecentlyUpdated { get { if (this.session["IsCartRecentlyUpdated"] != null) { return (bool)this.session["IsCartRecentlyUpdated"]; } else { this.sessi
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
}
将产品添加到购物车会进行回发,这样当产品刚刚添加到购物车时,我可以在购物车所在的常规母版页的页面加载中显示消息(ëg:product added Successfully):
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;
}
这个代码在本地运行great但在服务器上,将产品添加到购物车后,它不会显示消息,而是在第二页加载。。。
(我猜在服务器上,页面在会话变量更新之前加载了,这非常奇怪)
你知道为什么吗?我在代码中看不到任何问题…像这样的奇怪问题可能更容易用IIS express解决
您是否使用InProc会话,并且您的主站点是否由位于负载平衡器后面的多台服务器托管?添加产品时会发生什么情况?谁设置会话值,谁进行回发,顺序是什么?可能是服务器位于web场中,您的开发环境不是web场吗?我使用的是来自的共享web主机,因此无法查看其会话设置,但可以肯定的是,我在web.config中没有指定与此相关的任何内容。@克里斯蒂安:尝试在web.config中添加sessionStage元素,模式为SQLServer,并为会话存储配置SQL。