Groups > Asp .Net > HttpHandlers and HttpModules > Re: Inspecting the OutputStream in OnEndRequest




Inspecting the OutputStream in OnEndRequest

Inspecting the OutputStream in OnEndRequest
Fri, 14 Mar 2008 17:14:40 +000
Hi All,

One of the difficulties we've had with SoapExceptions is that ASP.NET
automatically sets the HTTP status code to 500.  But simply because we're
throwing an exception doesn't necessarily mean we want a 500 error (which means
"internal server error").  For instance, it is possible that nothing
went wrong on the server, but the request was malformed, or they didn't provide
the right credentials, and we want to throw back an exception for the client to
inspect.

In order to deal with this behavior of ASP.NET, I thought I could inspect the
outputstream in the OnEndRequest method of an HttpHandler that we use on our
site.  However, I can't figure out any way to actually see the current output
buffer or output stream!  Any pointers?

I tried this:

Line 214:            Stream output = app.Context.Response.OutputStream;
Line 215:            StreamReader reader = new StreamReader(output);
Line 216:            string outputString = reader.ReadToEnd();

Which threw "System.ArgumentException: Stream was not readable." 

I also tried:

Line 214:            Stream output = app.Context.Response.OutputStream;
Line 215:            output.Position = 0;
Line 216:            StreamReader reader = new StreamReader(output);
Line 217:            string outputString = reader.ReadToEnd();

Which threw "System.NotSupportedException: Specified method is not
supported."   -Josh
Post Reply
Re: Inspecting the OutputStream in OnEndRequest
Sat, 15 Mar 2008 18:47:34 +000
you cannot get the stream this way, you have to ovveride it. I demonstrate this
in my OpenSpace session at MIX last week. 

http://visitmix.com/blogs/OpenSpace/Fun-with-HttpModules/

More details will be available in an upcoming WROX BLOX. You can check out the
Blowry Compression module to see how this is done too.
Post Reply
Re: Inspecting the OutputStream in OnEndRequest
Mon, 17 Mar 2008 16:36:04 +000
Quoth:

"Chris Love gave a presentation on how to build HttpModules for ASP.NET and
the IIS7 integrated pipeline. The HttpModule interface gives developers an
opportunity to extend IIS7 and ASP.NET in different ways than otherwise
possible."

We've got XP Pro workstations, and Win2003 Servers.  I don't think it's possible
to get IIS7 on either or both of those, is it?

  -Josh
Post Reply
Re: Inspecting the OutputStream in OnEndRequest
Mon, 14 Apr 2008 04:44:17 +000
You do not need IIS 7, you can register the module with a specific web site in
the web.config. Here is my code from the full presentation,
http://professionalaspnet.com/archive/2008/04/09/Boston-Code-Camp-Wrap-Up.aspx
Post Reply
about | contact