System.Web.WebPages.WebPageBase.PopContext C# (CSharp) Method

PopContext() public method

public PopContext ( ) : void
return void
        public void PopContext()
        {
            // Using the CopyTo extension method on the _tempWriter instead of .ToString()
            // to avoid allocating large strings that then end up on the Large object heap.
            OutputStack.Pop();

            if (!String.IsNullOrEmpty(Layout))
            {
                string layoutPagePath = NormalizeLayoutPagePath(Layout);

                // If a layout file was specified, render it passing our page content.
                OutputStack.Push(_currentWriter);
                RenderSurrounding(
                    layoutPagePath,
                    _tempWriter.CopyTo);
                OutputStack.Pop();
            }
            else
            {
                // Otherwise, just render the page.
                _tempWriter.CopyTo(_currentWriter);
            }

            VerifyRenderedBodyOrSections();
            SectionWritersStack.Pop();
        }

Usage Example

Example #1
0
        public string ExecutCore(string basePath, string virtualPath, WebPageBase page)
        {
            var sb = new StringBuilder();
            using (var tw = new StringWriter(sb))
            {
                var context = new HttpContextWrapper(CreateContext(basePath, virtualPath, tw));
                var pageContext = new WebPageContext(context, page, null);
                page.PushContext(pageContext, tw);
                page.Execute();
                page.PopContext();
            }

            return sb.ToString();
        }