所以,我正在努力将HTML从标准的ASP.Net页面中删除。我已经重写了Render方法,如下所示:
protected override void Render(HtmlTextWriter writer)
{
MemoryStream memoryStream = new MemoryStream();
try
{
using (StreamWriter streamWriter = new StreamWriter(memoryStream))
{
var textWriter = new HtmlTextWriter(streamWriter);
base.Render(textWriter);
memoryStream.Position = 0;
using (StreamReader reader = new StreamReader(memoryStream))
{
var text = reader.ReadToEnd();
Response.Write(text);
reader.Close();
}
}
}
catch(ObjectDisposedException)
{
// The stream writer is already disposed?
}
finally
{
memoryStream.Dispose();
}
}
这适用于小于8.00 KB(8,200字节)的文件。如果文件大于该文件,则末尾的任何文本都将被截断。
有人有建议吗?
答案 0 :(得分:5)
也许,在textWriter.Flush()
致电后base.Render()
可以节省您的一天。