首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > C# >

session取不到值解决思路

2013-09-05 
session取不到值代码如下,第一页保存了一个Session[yonghuming],第二页 yhm Session[yonghuming].To

session取不到值
代码如下,第一页保存了一个Session["yonghuming"],第二页 yhm = Session["yonghuming"].ToString();却没有获得原Session的值。请高手赐教!
注:把第二页的 yhm = Session["yonghuming"].ToString();换成yhm = "aaa"; 时会有反应,说明已经进行到这一步了,只是取不到原Session的值。


第一页:

public partial class web_login : System.Web.UI.Page
{
    ......
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            
        }
    }
    protected void ImageButton1_Click(object sender, ImageClickEventArgs e)
    {
        if (this.txtCode.Text.ToString() == Request.Cookies["CheckCode"].Value.ToString())
        {
            if (bll.CheckLogin(Number, password))
            {
                if (bc.userLimit(Number))
                {
                    //将用户名保存到session
                   Session["yonghuming"] = this.txtNumber.ToString();
                   Session.Timeout = 600;

                   }
              }
          }
    }
}


第二页:

public partial class web_option : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
           .....
        }
    }
    protected void Repeater3_ItemDataBound(object sender, RepeaterItemEventArgs e)


    {
        int jibie = Convert.ToInt32(Session["jibie"]);
        
        String yhm = "";
        if (Session["yonghuming"] != null)
        {
             yhm = Session["yonghuming"].ToString();
        }
......
      }
}
[解决办法]
Session["yonghuming"] = this.txtNumber.ToString();
这个执行到了么?
[解决办法]
如果
 yhm = Session["yonghuming"].ToString();
改成
yhm = "aaa";后
yhm = "aaa";被执行了。
说明Session["yonghuming"]被赋值过了,因为Session["yonghuming"]不是null.

看看你有没有其他地方给Session["yonghuming"]赋值,还有在前面页面Session["yonghuming"] = this.txtNumber.ToString(); 设置断点, 看看Session["yonghuming"]是什么。
[解决办法]
代码断点跟踪一下在哪里session还有值呢?

热点排行