Never Dispose Objects from SPContext.Current
Last updated by Brook Jeynes [SSW] 10 months ago.See historyDisposing objects in SharePoint is important, but never do it with objects from SPContext.Current
. SharePoint will manage disposing these objects itself.
using (SPWeb web = SPContext.Current.Site.RootWeb)
{
//do something here
}
Figure: Using statement is trying to dispose current site object - it will cause exception
Just simply use "Current" object directly.
SPWeb web = SPContext.Current.Site.RootWeb;
//do something here
Figure: Use Current objects directly - don't need to dispose them
Love it
0
Agree
0
Disagree
0
No way
0