コード例 #1
0
        internal static void SetUpSessionState(HttpContextBase context, IHttpHandler handler, ConcurrentDictionary <Type, SessionStateBehavior?> cache)
        {
            WebPageHttpHandler webPageHandler = handler as WebPageHttpHandler;

            Debug.Assert(handler != null);
            SessionStateBehavior?sessionState = GetSessionStateBehavior(webPageHandler.RequestedPage, cache);

            if (sessionState != null)
            {
                // If the page explicitly specifies a session state value, return since it has the most priority.
                context.SetSessionStateBehavior(sessionState.Value);
                return;
            }

            WebPageRenderingBase page      = webPageHandler.StartPage;
            StartPage            startPage = null;

            do
            {
                // Drill down _AppStart and _PageStart.
                startPage = page as StartPage;
                if (startPage != null)
                {
                    sessionState = GetSessionStateBehavior(page, cache);
                    page         = startPage.ChildPage;
                }
            }while (startPage != null);

            if (sessionState != null)
            {
                context.SetSessionStateBehavior(sessionState.Value);
            }
        }
コード例 #2
0
        internal void ProcessRequestInternal(HttpContext context)
        {
            // enable dynamic validation for this request
            ValidationUtility.EnableDynamicValidation(context);
            context.Request.ValidateInput();

            try {
                HttpContextBase contextBase = new HttpContextWrapper(context);
                //WebSecurity.Context = contextBase;
                AddVersionHeader(contextBase);

                WebPageRenderingBase startPage = StartPage.GetStartPage(_webPage, StartPageFileName, WebPageHttpHandler.GetRegisteredExtensions());

                // This is also the point where a Plan9 request truly begins execution

                // We call ExecutePageHierarchy on the requested page, passing in the possible initPage, so that
                // the requested page can take care of the necessary push/pop context and trigger the call to
                // the initPage.
                _webPage.ExecutePageHierarchy(Util.CreatePageContext(context), context.Response.Output, startPage);

                if (ShouldGenerateSourceHeader(contextBase))
                {
                    GenerateSourceFilesHeader(_webPage.PageContext);
                }
            }
            catch (Exception e) {
                if (!HandleError(e))
                {
                    throw;
                }
            }
        }
コード例 #3
0
ファイル: WebPageBase.cs プロジェクト: belav/AspNetWebStack
        // This method is only used by WebPageBase to allow passing in the view context and writer.
        public void ExecutePageHierarchy(
            WebPageContext pageContext,
            TextWriter writer,
            WebPageRenderingBase startPage
            )
        {
            PushContext(pageContext, writer);

            if (startPage != null)
            {
                if (startPage != this)
                {
                    var startPageContext = WebPageContext.CreateNestedPageContext <object>(
                        parentContext: pageContext,
                        pageData: null,
                        model: null,
                        isLayoutPage: false
                        );
                    startPageContext.Page = startPage;
                    startPage.PageContext = startPageContext;
                }
                startPage.ExecutePageHierarchy();
            }
            else
            {
                ExecutePageHierarchy();
            }
            PopContext();
        }
            private WebViewPage CreatePage(ViewContext viewContext, System.IO.TextWriter writer, out WebPageContext pageContext, out WebPageRenderingBase startPage)
            {
                var webViewPage = (WebViewPage)Activator.CreateInstance(Compiled);

                if (!string.IsNullOrEmpty(MasterPath))
                {
                    LayoutSetter(webViewPage, MasterPath);
                }

                webViewPage.VirtualPath = Path;
                webViewPage.ViewContext = viewContext;
                webViewPage.ViewData = viewContext.ViewData;
                webViewPage.InitHelpers();

                pageContext = new WebPageContext(viewContext.HttpContext, webViewPage, null);

                startPage = null;
                if (StartPageGetter != null)
                {
                    startPage = StartPageGetter(webViewPage, "_ViewStart");
                }

                var asExecuting = webViewPage as WebPageExecutingBase;

                if (asExecuting != null)
                {
                    asExecuting.VirtualPathFactory = new PrecompiledVirtualPathFactory(CompiledTypeLookup, asExecuting.VirtualPathFactory);
                }

                return webViewPage;
            }
コード例 #5
0
        public static WebPageRenderingBase GetStartPage(
            WebPageRenderingBase page,
            string fileName,
            IEnumerable <string> supportedExtensions
            )
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(
                          String.Format(
                              CultureInfo.CurrentCulture,
                              CommonResources.Argument_Cannot_Be_Null_Or_Empty,
                              "fileName"
                              ),
                          "fileName"
                          );
            }
            if (supportedExtensions == null)
            {
                throw new ArgumentNullException("supportedExtensions");
            }

            // Use the page's VirtualPathFactory if available
            return(GetStartPage(
                       page,
                       page.VirtualPathFactory ?? VirtualPathFactoryManager.Instance,
                       HttpRuntime.AppDomainAppVirtualPath,
                       fileName,
                       supportedExtensions
                       ));
        }
コード例 #6
0
 private bool PrepareStartPage(WebPageContext pageContext, WebPageRenderingBase startPage)
 {
     if (startPage != null && startPage != this)
     {
         var startPageContext = WebPageContext.CreateNestedPageContext <object>(parentContext: pageContext, pageData: null, model: null, isLayoutPage: false);
         startPageContext.Page = startPage;
         startPage.PageContext = startPageContext;
         return(true);
     }
     return(false);
 }
コード例 #7
0
        internal static WebPageRenderingBase GetStartPage(
            WebPageRenderingBase page,
            IVirtualPathFactory virtualPathFactory,
            string appDomainAppVirtualPath,
            string fileName,
            IEnumerable <string> supportedExtensions
            )
        {
            // Build up a list of pages to execute, such as one of the following:
            // ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/sub/_pageStart.cshtml --> ~/sub/somepage.cshtml
            WebPageRenderingBase currentPage = page;
            var pageDirectory = VirtualPathUtility.GetDirectory(page.VirtualPath);

            // Start with the requested page's directory, find the init page,
            // and then traverse up the hierarchy to find init pages all the
            // way up to the root of the app.
            while (
                !String.IsNullOrEmpty(pageDirectory) &&
                pageDirectory != "/" &&
                PathUtil.IsWithinAppRoot(appDomainAppVirtualPath, pageDirectory)
                )
            {
                // Go through the list of supported extensions
                foreach (var extension in supportedExtensions)
                {
                    var virtualPath = VirtualPathUtility.Combine(
                        pageDirectory,
                        fileName + "." + extension
                        );

                    // Can we build a file from the current path?
                    if (virtualPathFactory.Exists(virtualPath))
                    {
                        var parentStartPage = virtualPathFactory.CreateInstance <StartPage>(
                            virtualPath
                            );
                        parentStartPage.VirtualPath        = virtualPath;
                        parentStartPage.ChildPage          = currentPage;
                        parentStartPage.VirtualPathFactory = virtualPathFactory;
                        currentPage = parentStartPage;
                        break;
                    }
                }

                pageDirectory = currentPage.GetDirectory(pageDirectory);
            }

            // At this point 'currentPage' is the root-most StartPage (if there were
            // any StartPages at all) or it is the requested page itself.
            return(currentPage);
        }
コード例 #8
0
        /// <summary>
        /// Returns either the root-most init page, or the provided page itself if no init page is found
        /// </summary>
        public static WebPageRenderingBase GetStartPage(WebPageRenderingBase page, string fileName, IEnumerable <string> supportedExtensions)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, CommonResources.Argument_Cannot_Be_Null_Or_Empty, "fileName"), "fileName");
            }
            if (supportedExtensions == null)
            {
                throw new ArgumentNullException("supportedExtensions");
            }

            // Build up a list of pages to execute, such as one of the following:
            // ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/sub/_pageStart.cshtml --> ~/sub/somepage.cshtml
            WebPageRenderingBase currentPage = page;
            var pageDirectory = VirtualPathUtility.GetDirectory(page.VirtualPath);

            // Start with the requested page's directory, find the init page,
            // and then traverse up the hierarchy to find init pages all the
            // way up to the root of the app.
            while (!String.IsNullOrEmpty(pageDirectory) && pageDirectory != "/" && Util.IsWithinAppRoot(pageDirectory))
            {
                // Go through the list of support extensions
                foreach (var extension in supportedExtensions)
                {
                    var path = VirtualPathUtility.Combine(pageDirectory, fileName + "." + extension);
                    if (currentPage.FileExists(path, useCache: true))
                    {
                        var factory         = currentPage.GetObjectFactory(path);
                        var parentStartPage = (StartPage)factory();

                        parentStartPage.VirtualPath = path;
                        parentStartPage.ChildPage   = currentPage;
                        currentPage = parentStartPage;

                        break;
                    }
                }

                pageDirectory = currentPage.GetDirectory(pageDirectory);
            }

            // At this point 'currentPage' is the root-most StartPage (if there were
            // any StartPages at all) or it is the requested page itself.
            return(currentPage);
        }
コード例 #9
0
        /// <summary>
        /// Returns either the root-most init page, or the provided page itself if no init page is found
        /// </summary>
        public static WebPageRenderingBase GetStartPage(WebPageRenderingBase page, string fileName, IEnumerable<string> supportedExtensions) {
            if (page == null) {
                throw new ArgumentNullException("page");
            }
            if (String.IsNullOrEmpty(fileName)) {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, CommonResources.Argument_Cannot_Be_Null_Or_Empty, "fileName"), "fileName");
            }
            if (supportedExtensions == null) {
                throw new ArgumentNullException("supportedExtensions");
            }

            // Build up a list of pages to execute, such as one of the following:
            // ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/sub/_pageStart.cshtml --> ~/sub/somepage.cshtml
            WebPageRenderingBase currentPage = page;
            var pageDirectory = VirtualPathUtility.GetDirectory(page.VirtualPath);

            // Start with the requested page's directory, find the init page,
            // and then traverse up the hierarchy to find init pages all the
            // way up to the root of the app.
            while (!String.IsNullOrEmpty(pageDirectory) && pageDirectory != "/" && Util.IsWithinAppRoot(pageDirectory)) {

                // Go through the list of support extensions
                foreach (var extension in supportedExtensions) {
                    var path = VirtualPathUtility.Combine(pageDirectory, fileName + "." + extension);
                    if (currentPage.FileExists(path, useCache: true)) {
                        var factory = currentPage.GetObjectFactory(path);
                        var parentStartPage = (StartPage)factory();

                        parentStartPage.VirtualPath = path;
                        parentStartPage.ChildPage = currentPage;
                        currentPage = parentStartPage;

                        break;
                    }
                }

                pageDirectory = currentPage.GetDirectory(pageDirectory);
            }

            // At this point 'currentPage' is the root-most StartPage (if there were
            // any StartPages at all) or it is the requested page itself.
            return currentPage;
        }
コード例 #10
0
        /// <summary>
        /// Returns either the root-most init page, or the provided page itself if no init page is found
        /// </summary>
        public static WebPageRenderingBase GetStartPage(WebPageRenderingBase page, string fileName, IEnumerable<string> supportedExtensions)
        {
            if (page == null)
            {
                throw new ArgumentNullException("page");
            }
            if (String.IsNullOrEmpty(fileName))
            {
                throw new ArgumentException(String.Format(CultureInfo.CurrentCulture, "Cannot be null or empty", "fileName"), "fileName");
            }
            if (supportedExtensions == null)
            {
                throw new ArgumentNullException("supportedExtensions");
            }

            // Use the page's VirtualPathFactory if available
            return GetStartPage(page, page.VirtualPathFactory, HttpRuntime.AppDomainAppVirtualPath, fileName, supportedExtensions);
        }
コード例 #11
0
        internal static WebPageRenderingBase GetStartPage(WebPageRenderingBase page, IVirtualPathFactory virtualPathFactory, string appDomainAppVirtualPath,
                                                          string fileName, IEnumerable<string> supportedExtensions)
        {
            // Build up a list of pages to execute, such as one of the following:
            // ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/somepage.cshtml
            // ~/_pageStart.cshtml --> ~/sub/_pageStart.cshtml --> ~/sub/somepage.cshtml
            WebPageRenderingBase currentPage = page;
            var pageDirectory = VirtualPathUtility.GetDirectory(page.VirtualPath);

            // Start with the requested page's directory, find the init page,
            // and then traverse up the hierarchy to find init pages all the
            // way up to the root of the app.
            while (!string.IsNullOrEmpty(pageDirectory))
            {
                // Go through the list of supported extensions
                foreach (var extension in supportedExtensions)
                {
                    var virtualPath = VirtualPathUtility.Combine(pageDirectory, fileName + "." + extension);

                    // Can we build a file from the current path?
                    if (virtualPathFactory.Exists(virtualPath))
                    {
                        var parentStartPage = virtualPathFactory.CreateInstance(virtualPath) as StartPage;
                        parentStartPage.VirtualPath = virtualPath;
                        parentStartPage.ChildPage = currentPage;
                        parentStartPage.VirtualPathFactory = virtualPathFactory;
                        currentPage = parentStartPage;
                        break;
                    }
                }
                
                pageDirectory = pageDirectory == "~/" 
                    ? null
                    : VirtualPathUtility.GetDirectory(pageDirectory);
            }

            // At this point 'currentPage' is the root-most StartPage (if there were
            // any StartPages at all) or it is the requested page itself.
            return currentPage;
        } 
コード例 #12
0
        // This method is only used by WebPageBase to allow passing in the view context and writer.
        public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage) {
            PushContext(pageContext, writer);

            if (startPage != null) {
                if (startPage != this) {
                    var startPageContext = Util.CreateNestedPageContext<object>(parentContext: pageContext, pageData: null, model: null, isLayoutPage: false);
                    startPageContext.Page = startPage;
                    startPage.PageContext = startPageContext;
                }
                startPage.ExecutePageHierarchy();
            }
            else {
                ExecutePageHierarchy();
            }
            PopContext();
        }
コード例 #13
0
        private void initialize(string templatePath, object dynamicModel = null, string fallbackTemplatePath = "/shared")
        {
            page = System.Web.WebPages.WebPageContext.Current.Page;
            baseSettingsOnContextGuess();
            setTemplatePath(templatePath);

            if (dynamicModel != null)
                this.dynamicModel = dynamicModel;
        }
コード例 #14
0
        private WebPageRenderingBase GetStartPage(WebPageRenderingBase page, string fileName)
        {
            WebPageRenderingBase currentPage = page;
            var pageDirectory = VirtualPathUtility.GetDirectory(page.VirtualPath);

            while (!String.IsNullOrEmpty(pageDirectory) && pageDirectory != "/")
            {
                var virtualPath = VirtualPathUtility.Combine(pageDirectory, fileName + ".cshtml");

                Type compiledType;
                if (_views.TryGetValue(virtualPath, out compiledType))
                {
                    var parentStartPage = (StartPage)Activator.CreateInstance(compiledType);
                    parentStartPage.VirtualPath = virtualPath;
                    parentStartPage.ChildPage = currentPage;
                    parentStartPage.VirtualPathFactory = page.VirtualPathFactory;
                    currentPage = parentStartPage;

                    break;
                }

                pageDirectory = VirtualPathUtility.GetDirectory(pageDirectory);
            }

            return currentPage;
        }
コード例 #15
0
        // This method is only used by WebPageBase to allow passing in the view context and writer.
        public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
        {
            PushContext(pageContext, writer);

            if (PrepareStartPage(pageContext, startPage))
            {
                startPage.ExecutePageHierarchy();
            }
            else
            {
                ExecutePageHierarchy();
            }
            PopContext();
        }
コード例 #16
0
 public WebPageContext(HttpContextBase context, WebPageRenderingBase page, object model)
 {
     HttpContext = context;
     Page        = page;
     Model       = model;
 }
コード例 #17
0
        public async Task ExecutePageHierarchyAsync(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
        {
            PushContext(pageContext, writer);

            if (PrepareStartPage(pageContext, startPage))
            {
                await startPage.ExecutePageHierarchyAsync().ConfigureAwait(false);
            }
            else
            {
                await ExecutePageHierarchyAsync().ConfigureAwait(false);
            }
            await PopContextAsync().ConfigureAwait(false);
        }
コード例 #18
0
 private bool PrepareStartPage(WebPageContext pageContext, WebPageRenderingBase startPage)
 {
     if (startPage != null && startPage != this)
     {
         var startPageContext = WebPageContext.CreateNestedPageContext<object>(parentContext: pageContext, pageData: null, model: null, isLayoutPage: false);
         startPageContext.Page = startPage;
         startPage.PageContext = startPageContext;
         return true;
     }
     return false;
 }
コード例 #19
0
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
 {
     this.PushContext(pageContext, writer);
       if (startPage != null)
       {
     if (startPage != this)
     {
       WebPageContext nestedPageContext = WebPageContext.CreateNestedPageContext<object>(pageContext, (IDictionary<object, object>) null, (object) null, false);
       nestedPageContext.Page = startPage;
       startPage.PageContext = nestedPageContext;
     }
     startPage.ExecutePageHierarchy();
       }
       else
     base.ExecutePageHierarchy();
       this.PopContext();
 }
コード例 #20
0
        public async Task ExecutePageHierarchyAsync(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
        {
            PushContext(pageContext, writer);

            if (PrepareStartPage(pageContext, startPage))
            {
                await startPage.ExecutePageHierarchyAsync().ConfigureAwait(false);
            }
            else
            {
                await ExecutePageHierarchyAsync().ConfigureAwait(false);
            }
            await PopContextAsync().ConfigureAwait(false);
        }
コード例 #21
0
        // This method is only used by WebPageBase to allow passing in the view context and writer.
        public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage)
        {
            PushContext(pageContext, writer);

            if (PrepareStartPage(pageContext, startPage))
            {
                startPage.ExecutePageHierarchy();
            }
            else
            {
                ExecutePageHierarchy();
            }
            PopContext();
        }
コード例 #22
0
ファイル: WebPageBase.cs プロジェクト: Rookian/Jericho
 /// <summary>
 /// Executes the code in a set of dependent web pages by using the specified context, writer, and start page.
 /// </summary>
 /// <param name="pageContext">The context data for the page.</param><param name="writer">The writer to use to write the executed HTML.</param><param name="startPage">The page to start execution in the page hierarchy.</param>
 public void ExecutePageHierarchy(WebPageContext pageContext, TextWriter writer, WebPageRenderingBase startPage);
コード例 #23
0
 public static bool IsAdmin(this WebPageRenderingBase webPage)
 {
     return(CurrentUser.IsAdmin);
 }
コード例 #24
0
 public WebPageContext(HttpContextBase context, WebPageRenderingBase page, object model) {
     HttpContext = context;
     Page = page;
     Model = model;
 }
コード例 #25
0
ファイル: UIHelper.cs プロジェクト: springzh/Piranha
 /// <summary>
 /// Default constructor.
 /// </summary>
 /// <param name="html"></param>
 public UIHelper(WebPageRenderingBase parent, HtmlHelper html)
 {
     Parent = parent ;
     Html = html ;
 }