当前位置: 代码迷 >> ASP.NET >> 不时出现-object reference not set to an instance of an boject
  详细解决方案

不时出现-object reference not set to an instance of an boject

热度:3102   发布时间:2013-02-25 00:00:00.0
时不时出现-object reference not set to an instance of an boject,
客户反映出现 object reference not set to an instance of an boject



我怀疑是的问题 session

我们网站有不少客户,这个问题偶尔会出现,大概1000个人有一个人会有这个问题吧,

是什么问题啊,
下面是cookiele和Session 的取值 
public static int EnterpriseID()
{
HttpContext context = HttpContext.Current ;

HttpCookie cookie=context.Request.Cookies["CookieLe"];

if(cookie.Values["enterpriseID"]==null||cookie.Values["enterpriseID"]=="")
{
//return 0;
}
else
{
                return int.Parse(jiemi_Des(cookie.Values["enterpriseID"]));
}

            if (context.Session["enterpriseID"] == null || context.Session["enterpriseID"].ToString() == "")
            {
                //return 0;
            }
            else
            {
                return int.Parse(context.Session["enterpriseID"].ToString());
            }
return 0;
}


就是这里偶尔会出错的。


public static bool EnterpriseAuthenticated()
{
HttpContext context = HttpContext.Current ;

            if (context.Session["enterpriseID"] == null || context.Session["enterpriseID"].ToString() == "")
            {
                //return(false); 
            }
            else
            {
                return (true);
            }
            if (context.Request.Cookies["CookieLe"] == null)
                return false;

HttpCookie cookie=context.Request.Cookies["CookieLe"];

//string name=cookie.Values["name"];
//string age=cookie.Values["age"];

if(cookie.Values["enterpriseID"]==null||cookie.Values["enterpriseID"]=="")
{

}
else
{
                int intmy = IsNumeric(cookie.Values["enterpriseID"]);
                if (intmy > 0)
                    return false;
                else
  相关解决方案