private WindowsImpersonationContext Impersonate() { try { var ssop = (SingleSignOnPrincipal)CSContext.Current.Context.User; var principal = (WindowsPrincipal)ssop.OriginalPrincipal; var id = (WindowsIdentity)principal.Identity; return(id.Impersonate()); } catch (Exception ex) { SPLog.UserInvalidCredentials(ex, string.Format("Enable Windows Authentication and set roleManager enabled=\"false\" : {0} {1}", ex.Message, ex.StackTrace)); } return(null); }
private void Init() { try { using (var clientContext = new SPContext(syncSettings.SPSiteURL, syncSettings.Authentication)) { SP.Web web = clientContext.Site.RootWeb; clientContext.Load(web, spweb => spweb.Title); clientContext.ExecuteQuery(); SPSiteTitle = web.Title; } } catch (Exception ex) { SPLog.UserInvalidCredentials(ex, String.Format("An exception of type {0} occurred while loading SharePoint web site {1}. The exception message is: {2}", ex.GetType().Name, syncSettings.SPSiteURL, ex.Message)); } }