protected void Page_PreInit(object sender, EventArgs e) { Uri redirectUrl; switch (SharePointContextProvider.CheckRedirectionStatus(Context, out redirectUrl)) { case RedirectionStatus.Ok: return; case RedirectionStatus.ShouldRedirect: Response.Redirect(redirectUrl.AbsoluteUri, endResponse: true); break; case RedirectionStatus.CanNotRedirect: Response.Write("An error occurred while processing your request."); Response.End(); break; } }
protected void Page_PreInit(object sender, EventArgs e) { Uri redirectUrl; switch (SharePointContextProvider.CheckRedirectionStatus(Context, out redirectUrl)) { case RedirectionStatus.Ok: return; case RedirectionStatus.ShouldRedirect: Response.Redirect(redirectUrl.AbsoluteUri, endResponse: true); break; case RedirectionStatus.CanNotRedirect: Response.Write("This page must be run as pare of a SharePoint App."); Response.End(); break; } }
/// <summary> /// Define o Contexto Sharepoint baseado no tipo de autenticação realizado /// </summary> /// <param name="context">Contexto Http obtido</param> private ClientContext StartObjectVariables(HttpContext httpContext, string siteCollectionUrl = null, string listName = null) { SharePointContextProvider ShpProvider = null; SharePointContextToken ContextToken = null; SharePointContext ShpContext = null; Uri SharePointUrl = null; ClientContext _currentContext = null; string AccessToken = null, contextTokenString = null; if (!WebConfigAddInDataRescue.IsHighTrustApp()) { ShpProvider = new SharePointAcsContextProvider(); ShpContext = ShpProvider.GetSharePointContext(httpContext); contextTokenString = ((SharePointAcsContext)ShpContext).ContextToken; ContextToken = TokenHelper.ReadAndValidateContextToken(contextTokenString, httpContext.Request.Url.Authority) ?? TokenHelper.ReadAndValidateContextToken(contextTokenString, SharePointUrl.Authority); } else { ShpProvider = new SharePointHighTrustContextProvider(); ShpContext = ShpProvider.GetSharePointContext(httpContext); } if (!WebConfigAddInDataRescue.IsHighTrustApp() && string.IsNullOrWhiteSpace(siteCollectionUrl)) { AccessToken = TokenHelper.GetAccessToken(ContextToken, SharePointUrl.Authority).AccessToken; _currentContext = ShpContext.GetClientContextWithAccessToken(SharePointUrl.ToString(), AccessToken); } else if (WebConfigAddInDataRescue.IsHighTrustApp() && string.IsNullOrWhiteSpace(siteCollectionUrl)) { AccessToken = ShpContext.UserAccessTokenForSPAppWeb ?? ShpContext.UserAccessTokenForSPHost; _currentContext = ShpContext.CreateAppOnlyClientContextForSPHost(); } else if (!string.IsNullOrWhiteSpace(siteCollectionUrl)) { AccessToken = ShpContext.UserAccessTokenForSPHost; _currentContext = TokenHelper.GetClientContextWithAccessToken(siteCollectionUrl, AccessToken); } return(_currentContext); }
/// <summary> /// Registriert die angegebene SharePointContextProvider-Instanz als aktuell. /// Diese sollte von "Application_Start()" in "Global.asax" aufgerufen werden. /// </summary> /// <param name="provider">Der als aktuell festzulegende SharePointContextProvider.</param> public static void Register(SharePointContextProvider provider) { if (provider == null) { throw new ArgumentNullException("provider"); } SharePointContextProvider.current = provider; }
/// <summary> /// Initialisiert die SharePointContextProvider-Standardinstanz. /// </summary> static SharePointContextProvider() { if (!TokenHelper.IsHighTrustApp()) { SharePointContextProvider.current = new SharePointAcsContextProvider(); } else { SharePointContextProvider.current = new SharePointHighTrustContextProvider(); } }
private SPClientContext() { clientContext = SharePointContextProvider.GetContext(); }
public static void RegisterProvider() { //Register the serializable context provider as the current SharePointContextProvider.Register(new SharePointAcsSerializableContextProvider()); }