日期:2014-05-20  浏览次数:20571 次

Gobal.asax出现异常:未将对象引用设置到对象的实例
如何解决?
源码:
public   class   Global   :   System.Web.HttpApplication
{
///   <summary>
///   必需的设计器变量。
///   </summary>
private   System.ComponentModel.IContainer   components   =   null;

public   Global()
{
InitializeComponent();
}

protected   void   Application_Start(Object   sender,   EventArgs   e)
{
                        string   path=Server.MapPath( "status.xml ");
                        XmlDocument   doc=new   XmlDocument();
doc.Load(path);
XmlNode   status=doc.SelectSingleNode( "total ");
        Application.Lock();
Application[ "total "]=Convert.ToInt32(status.Value);
Application[ "onLineNo "]=0;

Application.UnLock();


}
 
protected   void   Session_Start(Object   sender,   EventArgs   e)
{
this.Session.Timeout=20;
                                                        Application.Lock();
                                                      //异常详细信息:   System.NullReferenceException:   未将对象引用设置到对象的实例。
Application[ "onLineNo "]=(int)Application[ "onLineNo "]+1;
Application[ "total "]=(int)Application[ "total "]+1;
Application.UnLock();

}

protected   void   Application_BeginRequest(Object   sender,   EventArgs   e)
{

}

protected   void   Application_EndRequest(Object   sender,   EventArgs   e)
{

}

protected   void   Application_AuthenticateRequest(Object   sender,   EventArgs   e)
{

}

protected   void   Application_Error(Object   sender,   EventArgs   e)
{

}

protected   void   Session_End(Object   sender,   EventArgs   e)
{
Application.Lock();
Application[ "onLineNo "]=(int)Application[ "onLineNo "]-1;
Application.UnLock();

}

protected   void   Application_End(Object   sender,   EventArgs   e)
{
string   path= "status.xml ";
XmlDocument   doc=new   XmlDocument();
doc.Load(path);
XmlNode   status=doc.SelectSingleNode( "status ");
status.Value=Application[ "total "].ToString();;

}

------解决方案--------------------
从代码上没看出有什么问题,帮你顶了