Example #1
0
 public void WriteRedirectReponse(IHttpContext httpContext, string url, int statusCode = (int)HttpStatusCode.Redirect, bool replaceInHistory = false, bool allowSpaRedirect = false)
 {
     if (!DotvvmPresenter.DeterminePartialRendering(httpContext))
     {
         httpContext.Response.Headers["Location"] = url;
         httpContext.Response.StatusCode          = statusCode;
     }
     else
     {
         httpContext.Response.StatusCode  = 200;
         httpContext.Response.ContentType = "application/json";
         httpContext.Response.Write(DefaultViewModelSerializer.GenerateRedirectActionResponse(url, replaceInHistory, allowSpaRedirect));
     }
 }
 /// <summary>
 /// Renders the redirect response.
 /// </summary>
 public static void SetRedirectResponse(IOwinContext OwinContext, string url, int statusCode)
 {
     if (!DotvvmPresenter.DeterminePartialRendering(OwinContext))
     {
         OwinContext.Response.Headers["Location"] = url;
         OwinContext.Response.StatusCode          = statusCode;
     }
     else
     {
         OwinContext.Response.StatusCode  = 200;
         OwinContext.Response.ContentType = "application/json";
         OwinContext.Response.Write(DefaultViewModelSerializer.GenerateRedirectActionResponse(url));
     }
 }
Example #3
0
 public void WriteRedirectResponse(IHttpContext httpContext, string url, int statusCode = (int)HttpStatusCode.Redirect, bool replaceInHistory = false, bool allowSpaRedirect = false)
 {
     if (!DotvvmPresenter.DeterminePartialRendering(httpContext))
     {
         httpContext.Response.Headers["Location"] = url;
         httpContext.Response.StatusCode          = statusCode;
     }
     else
     {
         httpContext.Response.StatusCode  = 200;
         httpContext.Response.ContentType = "application/json";
         httpContext.Response
         .WriteAsync(DefaultViewModelSerializer.GenerateRedirectActionResponse(url, replaceInHistory, allowSpaRedirect))
         .GetAwaiter().GetResult();
         //   ^ we just wait for this Task. Redirect API never was async and the response size is small enough that we can't quite safely wait for the result
         //     .GetAwaiter().GetResult() preserves stack traces across async calls, thus I like it more that .Wait()
     }
 }
Example #4
0
        /// <summary>
        /// Renders the redirect response.
        /// </summary>
        /// <param name="forceRefresh"></param>
        public static void SetRedirectResponse(IOwinContext owinContext, string url, int statusCode, bool replaceInHistory = false, bool allowSpaRedirect = false)
        {
            if (!DotvvmPresenter.DeterminePartialRendering(owinContext))
            {
                owinContext.Response.Headers["Location"] = url;
                owinContext.Response.StatusCode          = statusCode;
            }
            else
            {
                //if (DotvvmPresenter.DetermineIsPostBack(owinContext) && DotvvmPresenter.DetermineSpaRequest(owinContext) && !url.Contains("//"))
                //{
                //    // if we are in SPA postback, redirect should point at #! URL
                //    url = "#!" + url;
                //}

                owinContext.Response.StatusCode  = 200;
                owinContext.Response.ContentType = "application/json";
                owinContext.Response.Write(DefaultViewModelSerializer.GenerateRedirectActionResponse(url, replaceInHistory, allowSpaRedirect));
            }
        }