博客园  :: 首页  :: 新随笔  :: 联系 :: 管理

 

using (SPWeb ospWeb = SPContext.Current.Web)
{
//...Logic
}

 

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

 Modified the code as shown below: 

using(SPSite spSite=new SPSite(SPContext.Current.Web.Url))
{
using (SPWeb spWeb = spSite.OpenWeb())
{
//...Logic
}
}

 MSDN click here