コード例 #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();
        }
コード例 #2
0
        private static void PreSendRequestHeaders(object sender, EventArgs e)
        {
            var context = ((HttpApplication)sender).Context;

            if (context.Error == null &&
                context.Response.StatusCode == 302 &&
                AjaxRedirectHelper.IsAjaxRequest(context.Request))
            {
                context.Response.StatusCode = AjaxRedirectHelper.AjaxRedirectStatusCode;
            }
        }
コード例 #3
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();
        }
コード例 #4
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);
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 public static bool IsAjaxRequest(this HttpRequest request)
 {
     return(AjaxRedirectHelper.IsAjaxRequest(request));
 }