对象引用未设置为对象实例 [英] object reference not set to instance of object

查看:86
本文介绍了对象引用未设置为对象实例的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

你好,

我有一个带树状视图的aspx页面.
在单击一个Treeview节点时,我创建了一个会话,例如. session ["projectname"] = treeview1.selectednode.text;

但有时会发生错误,即在上述会话中未将对象引用设置为对象的实例-

我已确保始终在用户转到另一个页面之前创建会话,为什么会这样呢?

我认为这与某些inproc,outproc会话管理有关,我是否必须添加以下几行:

Hello,

I have an aspx page with a treeview in it.
On clicking one treeview node I create a session, eg. session ["projectname"] = treeview1.selectednode.text;

but sometimes it happens that an error is thrown -- object reference not set to an instance of object for the above session--

I have ensured that the session always gets created before user going to another page, why this is happening?

I think is it related with some inproc, outproc session management, do I have to add below lines:

<sessionstate mode="InProc" timeout="60"></sessionstate>


在我的web.config中?这样可以解决问题吗?

请指导我.


In my web.config? will this solve the problem?

Please guide me..

thankyou very much in advance.

推荐答案

这仅表示``session ["projectname"]的值已被清除.会话超时时会发生这种情况.

如果您进行更改:
It simply means that the value of ''session["projectname"]'' is getting cleared out. This would be the case when session is getting timedout.

If you make the change:
<sessionstate mode="InProc" timeout="60"></sessionstate>


这样可以确保会话保持完整状态60分钟.一旦结束或IIS被重置/应用程序池回收,它将丢失.


This would make sure that the session is kept intact for 60 minutes. Once it''s over or IIS is reset/app-pool recycles then it will be lost.


工作进程可能被回收的原因有很多,因此会删除所有当前活动的会话.应用程序必须处理被丢弃的会话.生命周期超过可能的会话的任何内容都应存储在数据库中.会话仅用于存储临时内容,以方便使用.

(尽管您可以调整值以自动回收工作进程,但仍然可能在计算机上发出iisreset(也许在"wlbs挂起"之后),导致它立即失去所有会话状态,除非您使用连接到MS SQL Server的asp状态会话服务器.)

开始修改:
刚刚在http://www.xefteri.com/articles/show.cfm?id=14上找到了这个:

< processmodel>
timeout ="168:00:00"
...

第一个涉及timeout属性,该属性仅在指定为值的时间后创建一个新进程.例如,以上设置将在168小时或一周后自动开始新的过程.由于在向ASP.NET引擎发出第一个请求时实际上已创建了该过程,因此时钟在紧接第一个请求后立即开始.在内存和性能泄漏缓慢且需要定期IIS重置的情况下,此设置可能非常有用.

1 ...
2< processModel
3 requestLimit ="10000"
4 ...

第二种方法是使用requestLimit属性并为其提供Integer值.上面的10,000的值将在发出10,000个请求后开始新的过程.如果我们的Web服务器的性能在经过一定数量的请求后下降,而不是仅仅经过一定的时间而降低,则这将很有用.

1 ...
2< processModel
3 memoryLimit ="50"
4 ...

第三种方法是让您的系统查看该进程正在消耗多少内存.在上面的示例中,属性memoryLimit设置为50,这意味着如果该进程使用了​​总系统内存的50%以上,则该进程将被终止,将创建一个新的进程,并将所有现有请求重新分配给该新请求.无论存在多慢的内存泄漏情况,这都是非常有用的.

1 ...
2< processModel
3 responseDeadlockInterval ="00:03:00"
4 ...

第四种方法是使用responseDeadlockInterval属性.如果发生以下两种情况,则超过3分钟的时间设置将重新启动该过程:队列中有请求,但最近3分钟没有任何响应.

1 ...
2< processModel
3 pingFrequency ="00:00:30"
4 pingTimeout ="00:00:05"
5 ...

回收过程的第五种也是最后一种方法是结合使用pingFrequency和pingTimeout属性.系统以pingFrequency间隔ping ASP.NET进程,如果在pingTimeout时间间隔内没有响应,则重新启动它.

最终修改


干杯

Manfred
There are several reasons a worker process may get recycled thus dropping all currently active sessions. An application has to cope with sessions being dropped. Anything that needs to have a life time that exceeds a possible session should be stored in a DB. Sessions are meant to be used for storing temporary stuff for convenience only.

(Eventhough you can tune the values for the automatic recycling of the worker process, it can still happen that an iisreset is issued on a machine (after an ''wlbs suspend'' perhaps) causing it to instantly loose all session state, unless your using an asp state session server hooked up to a MS SQL Server.)

Start Modification:
Just found this on I found this on http://www.xefteri.com/articles/show.cfm?id=14 :

<processmodel>
timeout="168:00:00"
...

The first involves the timeout attribute, which simply creates a new process after the amount of time specified as a value. For example, the above setting will automatically start a new process after 168 hours, or one week. The time clock starts right after the first request is made, because the process is actually created when the first request to the ASP.NET engine is made. This setting can be extremely useful in scenarios where there is a slow leak in memory and performance, and periodic IIS resets are needed.

1 ...
2 <processModel
3 requestLimit="10000"
4 ...

A second way is to use the requestLimit attribute and give it an Integer value. A value of 10,000 like above, will start a new process after 10,000 requests have been made. This can be useful if our web server''s performance degrades after a set number of requests, instead of simply some amount of time past.

1 ...
2 <processModel
3 memoryLimit="50"
4 ...

A third way is to let your system watch how much memory the process is consuming. In the above example, the attribute memoryLimit is set to 50, which means that if the process uses more than 50% of total system memory then the process is killed , a new one is created and all existing requests are reassigned to the new one. This is extemely helpful is cases where a memory leak is present, no matter how slow the leak is.

1 ...
2 <processModel
3 responseDeadlockInterval="00:03:00"
4 ...

A fourth way of doing this is by using the responseDeadlockInterval attribute. The time setting above of 3 minutes will restart the process if two things happen: there are requests in the queue, but there have not been any responses for the last 3 minutes.

1 ...
2 <processModel
3 pingFrequency="00:00:30"
4 pingTimeout="00:00:05"
5 ...

The fifth and last way of recycling the process, is to use the pingFrequency and pingTimeout attributes in conjunction. The system pings the ASP.NET process at the pingFrequency interval, and restarts it if there is no response within the pingTimeout time interval.

End Modification


Cheers

Manfred


正如您所说的,您使用的是哪种会话模式.如果是inProc,则添加以下行
As you said, which session mode you are using.If inProc then add the line
<sessionstate mode="InProc" timeout="60"></sessionstate>


在配置文件中.

另外,在访问会话中的任何值之前,请先进行空检查,因为会话可能由于多种原因而被破坏.因此,为避免使用YSOD,请进行空检查,显示一些错误或在需要时重定向到其他页面.


in config file.

Also, before accessing any value from session, put a null check, because a session can be destroyed by many reasons. So to avoid YSOD, have a null check, show some error or redirect to some other page if required.


这篇关于对象引用未设置为对象实例的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆