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(); }
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; } }
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(); }
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); }
public static bool IsAjaxRequest(this HttpRequest request) { return(AjaxRedirectHelper.IsAjaxRequest(request)); }