コード例 #1
0
        public static ContextStatus CheckContextStatus(HttpControllerContext controllerContext, out Uri redirectUrl)
        {
            if (controllerContext == null)
            {
                throw new ArgumentNullException("controllerContext");
            }

            redirectUrl = null;

            if (SharePointApiControllerContextProvider.Current.GetSharePointContext(controllerContext) != null)
            {
                return(ContextStatus.Ok);
            }

            const string SPHasRedirectedToSharePointKey = "SPHasRedirectedToSharePoint";

            if (!string.IsNullOrEmpty(controllerContext.Request.GetQueryString(SPHasRedirectedToSharePointKey)))
            {
                return(ContextStatus.NotOk);
            }

            Uri spHostUrl = SharePointApiControllerContext.GetSPHostUrl(controllerContext.Request);

            if (spHostUrl == null)
            {
                return(ContextStatus.NotOk);
            }

            if (StringComparer.OrdinalIgnoreCase.Equals(controllerContext.Request.Method, "POST"))
            {
                return(ContextStatus.NotOk);
            }

            return(ContextStatus.NotOk);
        }
コード例 #2
0
        public SharePointApiControllerContext CreateSharePointContext(HttpControllerContext httpControllerContext)
        {
            if (httpControllerContext == null)
            {
                throw new ArgumentNullException("httpControllerContext");
            }

            // SPHostUrl
            Uri spHostUrl = SharePointApiControllerContext.GetSPHostUrl(httpControllerContext.Request);

            if (spHostUrl == null)
            {
                return(null);
            }

            // SPAppWebUrl
            string spAppWebUrlString = TokenHelper.EnsureTrailingSlash(httpControllerContext.Request.GetQueryString(SharePointApiControllerContext.SPAppWebUrlKey));
            Uri    spAppWebUrl;

            if (!Uri.TryCreate(spAppWebUrlString, UriKind.Absolute, out spAppWebUrl) ||
                !(spAppWebUrl.Scheme == Uri.UriSchemeHttp || spAppWebUrl.Scheme == Uri.UriSchemeHttps))
            {
                spAppWebUrl = null;
            }

            // SPLanguage
            string spLanguage = httpControllerContext.Request.GetQueryString(SharePointApiControllerContext.SPLanguageKey);

            if (string.IsNullOrEmpty(spLanguage))
            {
                return(null);
            }

            // SPClientTag
            string spClientTag = httpControllerContext.Request.GetQueryString(SharePointApiControllerContext.SPClientTagKey);

            if (string.IsNullOrEmpty(spClientTag))
            {
                return(null);
            }

            // SPProductNumber
            string spProductNumber = httpControllerContext.Request.GetQueryString(SharePointApiControllerContext.SPProductNumberKey);

            if (string.IsNullOrEmpty(spProductNumber))
            {
                return(null);
            }

            return(CreateSharePointContext(spHostUrl, spAppWebUrl, spLanguage, spClientTag, spProductNumber, httpControllerContext));
        }
コード例 #3
0
        public SharePointApiControllerContext GetSharePointContext(HttpControllerContext httpControllerContextContext)
        {
            if (httpControllerContextContext == null)
            {
                throw new ArgumentNullException("httpControllerContextContext");
            }

            Uri spHostUrl = SharePointApiControllerContext.GetSPHostUrl(httpControllerContextContext.Request);

            if (spHostUrl == null)
            {
                return(null);
            }

            SharePointApiControllerContext spContext = CreateSharePointContext(httpControllerContextContext);

            return(spContext);
        }