コード例 #1
0
 /// <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>
 private void VerifySpaRequest(DotvvmRequestContext 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.OwinContext.Request.Uri.AbsoluteUri);
         }
     }
 }
コード例 #2
0
        /// <summary>
        /// Checks that the content page does not contain invalid content.
        /// </summary>
        private List<Content> GetChildPageContents(DotvvmView childPage, List<ContentPlaceHolder> parentPlaceHolders)
        {
            // make sure that the body contains only whitespace and Content controls
            if (!childPage.Children.All(c => (c is RawLiteral && ((RawLiteral)c).IsWhitespace) || (c is Content)))
            {
                throw new Exception("If the page contains @masterpage directive, it can only contain white space and <dot:Content /> controls!");    // TODO: exception handling
            }

            // make sure that the Content controls are not nested in other elements
            var contents = childPage.GetAllDescendants().OfType<Content>()
                .Where(c => !(bool) c.GetValue(Internal.IsMasterPageCompositionFinishedProperty))
                .ToList();
            if (contents.Any(c => c.Parent != childPage))
            {
                throw new Exception("The control <dot:Content /> cannot be placed inside any control!");    // TODO: exception handling
            }

            return contents;
        }