ASP.Net Final Rendering Page Event

拜拜、爱过 提交于 2019-12-08 04:48:36

问题


Perhaps my previous question on output caching output caching was too complex.

Let's simplify.

How can I get the final, "ready for sending" rendered HTML from a page (or control) event in ASP.Net? I assume that this will be the same content that will be used for the output cache, so could be queried to find out what is about to be placed into the cache.


回答1:


Code copied from: http://aspcode.net/Last-second-HTML-changes-in-your-ASPNET-page.aspx

protected override void Render(HtmlTextWriter writer) 
{ 
    using(System.IO.MemoryStream msOur = new System.IO.MemoryStream()) 
    { 
        using(System.IO.StreamWriter swOur = new System.IO.StreamWriter(msOur)) 
        { 
            HtmlTextWriter ourWriter = new HtmlTextWriter(swOur); 
            base.Render(ourWriter); 
            ourWriter.Flush(); 
            msOur.Position = 0; 
            using(System.IO.StreamReader oReader = new System.IO.StreamReader(msOur)) 
            { 
                string sTxt = oReader.ReadToEnd();                     
                Response.Write(sTxt); 
                oReader.Close(); 
            } 
        } 
    } 
} 


来源:https://stackoverflow.com/questions/4370249/asp-net-final-rendering-page-event

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!