public override void OnActionExecuting(ActionExecutingContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException(nameof(filterContext));
            }
            var context = new RequestContext(filterContext.HttpContext);

            switch (CustomSharePointContextProvider.CheckRedirectionStatus(context, out var redirectUrl))
            {
            case CustomSharePointContextProvider.RedirectionStatus.Ok:
                return;

            case CustomSharePointContextProvider.RedirectionStatus.ShouldRedirect:
                filterContext.Result = new RedirectResult(redirectUrl.AbsoluteUri);
                break;

            case CustomSharePointContextProvider.RedirectionStatus.CanNotRedirect:
                filterContext.Result = new ViewResult {
                    ViewName = "Error"
                };
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }
        }
 static CustomSharePointContextProvider()
 {
     if (!TokenHelper.IsHighTrustApp())
     {
         Current = new CustomSharePointAcsContextProvider();
     }
     else
     {
         Current = new CustomSharePointHighTrustContextProvider();
     }
 }
Example #3
0
        public override void OnActionExecuting(HttpActionContext filterContext)
        {
            if (filterContext == null)
            {
                throw new ArgumentNullException(nameof(filterContext));
            }
            var context = new ControllerContext(filterContext);
            var result  = CustomSharePointContextProvider.CheckRedirectionStatus(context, out _);

            if (result == CustomSharePointContextProvider.RedirectionStatus.Ok)
            {
                return;
            }
            filterContext.Response = filterContext.Request.CreateErrorResponse(
                HttpStatusCode.MethodNotAllowed, "Could not create context");
        }
 public static void Register(CustomSharePointContextProvider provider)
 {
     Current = provider ?? throw new ArgumentNullException(nameof(provider));
 }