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

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
 
K

kellygreer1

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
 
J

John Timney \(MVP\)

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,997
Messages
2,570,240
Members
46,830
Latest member
HeleneMull

Latest Threads

Top