求助:我再一个页面的后台代码声明了一个变量如:private int customerId = 0;
protected void Page_Load(object sender, EventArgs e)
{
   if (Session["CustomerID"] + "" != "")
   {
          customerId =int.Parse(Session["CustomerID"]);          
   }
}当A访问时customerId 为A的customerId ,此时B访问后A的customerId 就成为B的customerId 了,但customerId 不是static
的啊,这是为什么?各位大神,能说一下吗?

解决方案 »

  1.   

    if (Session["CustomerID"] + "" != "")这个判断是什么意义?还有B怎么能能访问A的Session?
      

  2.   

    这个判断
    if (Session["CustomerID"].ToString() != "")
    或者
    if (Session["CustomerID"]=null)看看Session["CustomerID"]的类型。Session是标识用户身份你建立个C页面 只要Session不丢失 一样可以访问到。去查查Session的用法和概念
      

  3.   

    if (Session["CustomerID"] != null &&  Session["CustomerID"].ToString() != "")
      {
    try{
      customerId =int.Parse(Session["CustomerID"].ToString());  
    }catch(Exception ex){ customerId = 0 ;}
      }
      

  4.   

    Session["CustomerID"] + "" != ""是判断Session["CustomerID"]是否为空,防止int.Parse(Session["CustomerID"])出错,问题找出来了,是页面的生存周期问题。