using (SPWeb ospWeb = SPContext.Current.Web)
{
//...Logic
}
{
//...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