Esempio n. 1
0
        public void AjaxRedirect_HttpContextBase_NonAjax(bool endResponse)
        {
            // Arrange
            m_mockHttpContext.Setup(context => context.Response.Redirect("/c/a/i", endResponse)).Verifiable();

            // Act
            AjaxRedirectHelper.AjaxRedirect(m_mockHttpContext.Object, "/c/a/i", endResponse);

            // Assert
            m_mockHttpContext.Verify();
        }
Esempio n. 2
0
        public void AjaxRedirect_HttpContextBase_Ajax(bool endResponse)
        {
            // Arrange
            m_mockHttpContext.Setup(context => context.Request["X-Requested-With"]).Returns("XMLHttpRequest");
            m_mockHttpContext.SetupProperty(context => context.Response.StatusCode);
            m_mockHttpContext.Setup(context => context.Response.AddHeader("Location", "/c/a/i")).Verifiable();

            // Act
            AjaxRedirectHelper.AjaxRedirect(m_mockHttpContext.Object, "/c/a/i", endResponse);

            // Assert
            Assert.Equal(AjaxRedirectHelper.AjaxRedirectStatusCode, m_mockHttpContext.Object.Response.StatusCode);
            m_mockHttpContext.Verify();
        }
Esempio n. 3
0
        public static void AjaxRedirect(ControllerContext context, string url)
        {
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }

            if (context.IsChildAction)
            {
                throw new InvalidOperationException(Properties.Resources.RedirectAction_CannotRedirectInChildAction);
            }

            context.Controller.TempData.Keep();
            AjaxRedirectHelper.AjaxRedirect(context.HttpContext, url, false);
        }
        public bool HandleException(Exception ex)
        {
            if (string.IsNullOrEmpty(RedirectUrl) || ex == null)
            {
                return(false);
            }

            if (typeof(TException).IsAssignableFrom(ex.GetType()) ||
                (CheckInner && ExceptionHelper.Find <TException>(ex.InnerException) != null))
            {
                var context = HttpContext.Current;
                context.Server.ClearError();
                AjaxRedirectHelper.AjaxRedirect(context, BuildAspxErrorPath(context.Request.Url));
                return(true);
            }

            return(false);
        }