Asp.net控制输出到客户端的Html

来源:互联网 发布:织梦cms utf8 编辑:程序博客网 时间:2024/06/15 10:10

此项功能的要点在于页面重载Page.Render方法:  

此功能可用于表情的解析等等

        protected override void Render(HtmlTextWriter writer)

        {
            string content = string.Empty;
            StringWriter sWriter = new StringWriter();
            HtmlTextWriter htWriter = new HtmlTextWriter(sWriter);
            try
            {
                base.Render(htWriter);
                htWriter.Close();
                content = sWriter.ToString();
                string newContent = content.Replace("[test]", "<img src=test.png/>");
                writer.Write(newContent);
            }
            catch
            {
            }
            finally
            {
                sWriter.Dispose();
                htWriter.Close();
                htWriter.Dispose();
            }
        }