求助:我再一个页面的后台代码声明了一个变量如: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
的啊,这是为什么?各位大神,能说一下吗?
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
的啊,这是为什么?各位大神,能说一下吗?
if (Session["CustomerID"].ToString() != "")
或者
if (Session["CustomerID"]=null)看看Session["CustomerID"]的类型。Session是标识用户身份你建立个C页面 只要Session不丢失 一样可以访问到。去查查Session的用法和概念
{
try{
customerId =int.Parse(Session["CustomerID"].ToString());
}catch(Exception ex){ customerId = 0 ;}
}