覆盖页面渲染/StreamReader 大小限制?
因此,我正在尝试从标准 ASP.Net 页面中获取 HTML。我已经重写了 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 字节)的文件非常有效。如果文件大于该值,则末尾的所有文本都会被截断。
有人有建议吗?
So, I'm playing around with getting the HTML out of a standard ASP.Net Page. I've overridden the Render method, as so:
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();
}
}
This works great on files that are less than 8.00 KB (8,200 bytes). If the file is larger than that, any text at the end is being cut off.
Does anyone have an suggestions?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
也许,调用
base.Render()
后的textWriter.Flush()
会拯救你的一天。Maybe,
textWriter.Flush()
after a call tobase.Render()
will save your day.