Thursday, January 28, 2010

Access denied while updating web objects.

We get Access denied even if the code is running under 'RunWithElevatedPrivileges' and AllowUnsafeUpdates is set to True.

Solution :
Instead of using RunWithElevatedPrivileges command , create a instance of SPSite with system account user token.

SPSite currentSite = SPContext.Current.Site;

using(SPSite _oSite = new SPSite(currentSite.ID, urrentSite.SystemAccount.UserToken))
{
// Do something
}

No comments: