开发者

Override Render of a page / StreamReader size limit?

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))
            {
                va开发者_如何学Gor 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?


Maybe, textWriter.Flush() after a call to base.Render() will save your day.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜