Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

image

如上图所示,如果你的页面出现这样的Error时,请检查你的程序中,是否出现了类似一下的代码块:

Trying to use an SPWeb object that has been closed or disposed and is no longer valid.

在以上代码中,可以看到

TestFunction1和TestFunction2中获取SPSite的的方式是:SPSite site =SPContext.Current.Site,这样以来,在程序执行中,TestFunction2中的site释放后,TestFunction1中后续代码在调用site信息,就会找不到site,因为它已经被释放掉了,所以会出以上问题。

所以代码可改为:

The great code

这样,问题便解决啦。

原文地址:https://www.cnblogs.com/qixing_gan/p/2981727.html