乱用Session后果

 protected void Page_Load(object sender, EventArgs e)
        {
            
            if (!IsPostBack)
            {
                Session["OrganCode"] = "Z";
            }

            for (int i = 0; i < 30000; i++)
            {
                string zstr = Session["OrganCode"].ToString();
                if (string.IsNullOrEmpty(zstr))
                {
                    Label1.Text = "session is null";
                }
            }
        }

 

这样用,没有问题。

 

 但类似的使用,在某些情况下,比如:用户点击转到其他页面时,会出现其中几个session为“”的情况。

 改为

 protected void Page_Load(object sender, EventArgs e)

        {

            // this.FormView3.ChangeMode(FormViewMode.ReadOnly);

            if (!IsPostBack)

            {

                Session["OrganCode"] = "Z";

            }

string zz= Session["OrganCode"].ToString();

            for (int i = 0; i < 30000; i++)

            {

                string zstr = zz;

                if (string.IsNullOrEmpty(zstr))

                {

                    Label1.Text = "session is null";

                }

            }

        } 

 

all done! 

 

Session乱用,即使不在乎性能,但也会有其他问题。所以说习惯还是要好才行。

posted on 2010-07-22 11:17  公众号73只蚂蚁  阅读(724)  评论(2编辑  收藏  举报

导航