PHP's output buffer and ASP.NET's Response.OutputStream

  • Thread starter Thread starter kellygreer1
  • Start date Start date
K

kellygreer1

PHP will alllow you to build up an entire page and before sending that
out as the response.... you can grab all the text and do search and
replaces, add comments, make more CSS/XHTML compliant, etc...

I have bee trying to do the same thing in ASP.NET by manipulating the
Response.OutputStream.
I keep getting the error:
Exception Details: System.ArgumentException: Stream was not readable.
On this line:
StreamReader sr = new StreamReader(Response.OutputStream, true);

What is the correct way to read from this stream? and then push back
in your own contents and then let the Response complete?

Thanks,
Kelly Greer
(e-mail address removed)
replace nospam with yahoo
 
You can do that by overriding the render event, completly replacing the HTML
should you choose to do so.....or in an ihttpmodule you can add a
response.filter method

http://microsoft.apress.com/asptodayarchive/73666/enforcing-xhtml-com...

Regards

John Timney (MVP)http://www.johntimney.comhttp://www.johntimney.com/blog

Thanks for the info. So when you Override the Render method is this
the only place where you can manipulate the Response.OutputStream? or
do you get the existing "Rendered Text" as a String from somewhere
else?

Thanks,
Kelly
 
Each control has a render method, as does page. Heres an example you can
add to a page to see the results.

protected override void Render(HtmlTextWriter writer) {
// extract all html and override <h2>News List</h2>
System.IO.StringWriter str = new System.IO.StringWriter();
HtmlTextWriter wrt = new HtmlTextWriter(str);
// render html
base.Render(wrt); //CAPTURE THE CURRENT PAGE HTML SOURCE AS STRING
wrt.Close();
string html = str.ToString();
html = html.Replace("text", "<h2>TEXT</h2>");
// write the new html to the page
writer.Write(html);
}

Regards

John Timney (MVP)
http://www.johntimney.com
http://www.johntimney.com/blog
 
Back
Top