I'm often using pattern where I create class Workspace. This class has some basic functionality and on of them is opening of webs, and also web in privilege mode:
public class Workspace : IDisposable { public SPWeb AppWebPrivileged { get { if (this.appWebPrivileged == null) { lock (_myLock) { if (this.appWebPrivileged == null) { SPSecurity.RunWithElevatedPrivileges(() => { if (this.sitePrivileged == null) { this.sitePrivileged = new SPSite(this.Site.ID); } this.appWebPrivileged = this.sitePrivileged.OpenWeb(this.AppWeb.ID); this.appWebPrivileged.AllowUnsafeUpdates = true; }); } } } return this.appWebPrivileged; } } ..... } Then in some method of Workspace class I can use this variable like this:
this.AppWebPrivileged.GetFile(fileName); This works great, but currently we switch from http to https protocol. If now I call this method: this.AppWebPrivileged.GetFile(fileName); I get error: Null pointer exception.
If i put code this.AppWebPrivileged.GetFile(fileName); in same SPSecurity.RunWithElevatedPrivileges where is web opened, file can be loaded.
Is there any possibility how to open Privilege Web in one place of code, and then use this opened web in another place?
Is this pattern totaly wrong? and i have to still execute all code in privilege delegate, not only open web?
I have this problem only when using HTTPS protocol. When using HTTP, I'm possible to firstly open web in privilege mode and then use it in not privilege mode as privilege web.