protected override void OnPageException(IDotvvmRequestContext context, Exception exception)
        {
            context.IsPageExceptionHandled = true;
            context.RedirectToUrl("/error500");

            base.OnPageException(context, exception);
        }
    /// <summary>
    /// Returns the redirect response and interrupts the execution of current request.
    /// </summary>
    public static void RedirectToRoute(this IDotvvmRequestContext context, string routeName, object newRouteValues = null, bool replaceInHistory = false, bool allowSpaRedirect = true, string urlSuffix = null, object query = null)
    {
        var route = context.Configuration.RouteTable[routeName];
        var url   = route.BuildUrl(context.Parameters, newRouteValues) + UrlHelper.BuildUrlSuffix(urlSuffix, query);

        context.RedirectToUrl(url, replaceInHistory, allowSpaRedirect);
    }
Exemplo n.º 3
0
        protected override void OnPageException(IDotvvmRequestContext context, Exception exception)
        {
            context.IsPageExceptionHandled = true;
            context.RedirectToUrl("/error500");

            base.OnPageException(context, exception);
        }
Exemplo n.º 4
0
        protected override Task OnPageExceptionAsync(IDotvvmRequestContext context, Exception exception)
        {
            if (!context.HttpContext.Request.Query.ContainsKey("redirected"))
            {
                context.RedirectToUrl(context.HttpContext.Request.Url.AbsoluteUri + "?redirected=true");
            }

            return(base.OnPageExceptionAsync(context, exception));
        }
Exemplo n.º 5
0
    public static void RedirectToLocalUrl(this IDotvvmRequestContext context, string url, bool replaceInHistory = false, bool allowSpaRedirect = false)
    {
        if (!UrlHelper.IsLocalUrl(url))
        {
            throw new InvalidOperationException($"The URL '{url}' is not local or contains invalid characters!");
        }

        context.RedirectToUrl(url, replaceInHistory, allowSpaRedirect);
    }
 /// <summary>
 /// If the request is SPA request, we need to verify that the page contains the same SpaContentPlaceHolder.
 /// Also we need to check that the placeholder is the same.
 /// </summary>
 protected void VerifySpaRequest(IDotvvmRequestContext context, DotvvmView page)
 {
     if (context.IsSpaRequest)
     {
         var spaContentPlaceHolders = page.GetAllDescendants().OfType <SpaContentPlaceHolder>().ToList();
         if (spaContentPlaceHolders.Count > 1)
         {
             throw new Exception("Multiple controls of type <dot:SpaContentPlaceHolder /> found on the page! This control can be used only once!");   // TODO: exception handling
         }
         if (spaContentPlaceHolders.Count == 0 || spaContentPlaceHolders[0].GetSpaContentPlaceHolderUniqueId() != context.GetSpaContentPlaceHolderUniqueId())
         {
             // the client has loaded different page which does not contain current SpaContentPlaceHolder - he needs to be redirected
             context.RedirectToUrl(context.HttpContext.Request.Url.AbsoluteUri.Replace("/" + HostingConstants.SpaUrlIdentifier, ""));
         }
     }
 }
Exemplo n.º 7
0
 protected override Task OnPageExceptionAsync(IDotvvmRequestContext context, Exception exception)
 {
     context.IsPageExceptionHandled = true;
     context.RedirectToUrl("/error500");
     return(Task.CompletedTask);
 }