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

PushContext() public method

public PushContext ( System.Web.WebPages.WebPageContext pageContext, TextWriter writer ) : void
pageContext System.Web.WebPages.WebPageContext
writer System.IO.TextWriter
return void
        public void PushContext(WebPageContext pageContext, TextWriter writer)
        {
            _currentWriter = writer;
            PageContext = pageContext;
            pageContext.Page = this;

            InitializePage();

            // Create a temporary writer
            _tempWriter = new StringBlockWriter(CultureInfo.InvariantCulture);

            // Render the page into it
            OutputStack.Push(_tempWriter);
            SectionWritersStack.Push(new Dictionary<string, SectionWriter>(StringComparer.OrdinalIgnoreCase));

            // If the body is defined in the ViewData, remove it and store it on the instance
            // so that it won't affect rendering of partial pages when they call VerifyRenderedBodyOrSections
            if (PageContext.BodyAction != null)
            {
                _body = PageContext.BodyAction;
                PageContext.BodyAction = null;
            }
        }

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();
        }