views:

34

answers:

4

I am formatting html in my admin page and wants to send this html as part of Response object. I am redirecting to HttpHandler (Preview.ashx) using Response.Redirect, but how am I supposed to send that html within response and read it from httphandler using HttpContext object in my Handler?

A: 

You will need to store the HTML somewhere and send a key to your handler on the QueryString. For example, you could put it in session with a GUID key, and send the GUID on the QueryString like Preview.ashx?htmlId=000...

You could also store it in a database, Cache, or Application. just some ideas...

dave thieben
How about sending html as part of that response headers as namevaluecollection, i can send the keys of namevaluecollection via query string and in handler i can get each key and search within the response header for the value (html)? Would that be an efficient approach?
Ashar Syed
That would require the browser to send back the same headers you are sending, which I don't think happens. Even if there is a way to do it, you are now allowing the client access to possibly sensitive data.
dave thieben
A: 

How about sending html as part of that response headers as namevaluecollection, i can send the keys of namevaluecollection via query string and in handler i can get each key and search within the response header for the value (html)? Would that be an efficient approach?

Ashar Syed
A: 

Since the user is presumably logged in (admin panel) your could put the html in session and pull it out later in the handler. You will need to implement the IRequiresSessionState in your ashx, though. http://msdn.microsoft.com/en-us/library/system.web.sessionstate.irequiressessionstate.aspx

SquidScareMe
A: 

I think you might want to look at the HttpServerUtility.Transfer() method. While Response.Redirect will create a response to the client instructing the client to navigate to the new page (the .ashx page in your case) a server transfer will do a "server-side redirect" to the page and your server state will be maintained so you can store the html in a context variable where it can be retrieved by the logic in the ashx handler.

Mark