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

asp.net 2005 严重求救

2011-12-21 
asp.net 2005 紧急求救我的程序在本机运行正常,但发布到服务器时,经常出现如下错误,刷新一下就好了,但进入

asp.net 2005 紧急求救
我的程序在本机运行正常,但发布到服务器时,经常出现如下错误,刷新一下就好了,但进入网页后台一点错误都没有,前台出现错误时偶然的

Object   reference   not   set   to   an   instance   of   an   object.  
Description:   An   unhandled   exception   occurred   during   the   execution   of   the   current   web   request.   Please   review   the   stack   trace   for   more   information   about   the   error   and   where   it   originated   in   the   code.  

Exception   Details:   System.NullReferenceException:   Object   reference   not   set   to   an   instance   of   an   object.

Source   Error:  

An   unhandled   exception   was   generated   during   the   execution   of   the   current   web   request.   Information   regarding   the   origin   and   location   of   the   exception   can   be   identified   using   the   exception   stack   trace   below.    

Stack   Trace:  


[NullReferenceException:   Object   reference   not   set   to   an   instance   of   an   object.]
      Controls_ContactBar.Page_Load(Object   sender,   EventArgs   e)   in   e:\lq\ASPDOTNET05\ECSystem\WebUI\Controls\ContactBar.ascx.cs:19
      System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr   fp,   Object   o,   Object   t,   EventArgs   e)   +15
      System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object   sender,   EventArgs   e)   +34
      System.Web.UI.Control.OnLoad(EventArgs   e)   +99
      System.Web.UI.Control.LoadRecursive()   +47
      System.Web.UI.Control.LoadRecursive()   +131
      System.Web.UI.Control.LoadRecursive()   +131
      System.Web.UI.Control.LoadRecursive()   +131
      System.Web.UI.Page.ProcessRequestMain(Boolean   includeStagesBeforeAsyncPoint,   Boolean   includeStagesAfterAsyncPoint)   +1061

 


--------------------------------------------
Version   Information:   Microsoft   .NET   Framework   Version:2.0.50727.42;   ASP.NET   Version:2.0.50727.42  


前台和后台相比多了   cache,母板,和用户控件

要是这些导致出错,本机测试也应该出现的,本机测试一点问题都没

郁闷阿,各位高手帮忙了。。。

[解决办法]
检查代码e:\lq\ASPDOTNET05\ECSystem\WebUI\Controls\ContactBar.ascx.cs:19
[解决办法]
用异常 捕获
e:\lq\ASPDOTNET05\ECSystem\WebUI\Controls\ContactBar.ascx.cs:19

这里的错误.
[解决办法]

舍不得给代码
[解决办法]
System.NullReferenceException: Object reference not set to an instance of an object.
int ID = (int)HttpContext.Current.Cache[ "ID "];
HttpContext.Current.Cache[ "ID "]为null时就会引发,加个if过滤一下
[解决办法]
同意楼上 另外 本机测试没问题的话 建议你检查
1 web.config
2 数据内容


[解决办法]
(1)本机环境是不是IIS,IIS版本是否一致,另外,在本机是否与生产环境一下长时间运行。
(2)查找一下关于IIS的进程回收,垃圾回收等内容。
(3)不用cache,改用静态类存贮,看看是否还会出现问题。

总体上,怀疑cache被IIS回收或其它原因造成进程IIS重启后cache被清空。
[解决办法]
HttpContext.Current.Cache[ "ID "]为null

你在19行之前有用if判断一下它是否为null吗?不读取就尝试用(int)来强类型转换就会造成潜在的危险,因为Cache和Session这类东西随时可能为null。因此,以后凡是类似的情景,你都必须先判断,用if或者用?:。
[解决办法]
我在 Application_BeginRequest里有:
if(HttpContext.Current.Cache[ "ID "]==null)
{
初始化cache
}

即使在页面里cache为空,请求时也会被初始化啊

Application_BeginRequest 不是执行每次请求前先执行的么?

(1)加测试语句,看是否的确在请求之间执行,并输出cache值。特别是出错的时候要注意。
(2)如果以上没有问题,那么错误不在这个语句上。

[解决办法]
未将对象引用设置到实例,有个对象没有初始化就开始使用了,那个
cache没有初始化或者没有值就开始使用了,先后问题吧

热点排行