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

.net自定义种中Session 存值说未将对象引用设置到对象的实例

2013-09-29 
.net自定义类中Session 存值说未将对象引用设置到对象的实例 public int intUserID{set{if (value ! null

.net自定义类中Session 存值说未将对象引用设置到对象的实例
 public int intUserID
        {
            set
            {
                if (value != null)
                {
                    int intUserID;
                    if (int.TryParse(value.ToString(), out intUserID))
                    {
                        
                        HttpContext.Current.Session["UserID"] = intUserID;
                    }

                }
            }
            get
            {

                if (HttpContext.Current.Session["UserID"] == null)
                {
                    return -1;
                }
                else
                {
                    try
                    {
                        return Convert.ToInt32(HttpContext.Current.Session["UserID"].ToString());

                    }
                    catch (Exception)
                    {
                        return -1;
                    }
                }
            }
        }

[解决办法]
HttpContext是不是null
HttpContext.Current是不是null
HttpContext.Current.Session["UserID"]是不是null

热点排行