Accessing Session after a call to Response.End()

I have a custom http module which does some post processing on a request. This processing runs during the PostRequestHandlerExecute event, and it modifies the SessionState.

I have a third party control which is implementing what their own Callback mechanism. Essentially the component is rendering some XML to the buffer in the Render event of the control after which it calls Response.End().

Because it calls Response.End() none of the other events in the pipeline are being fired. I'm trying to figure out a way to still get my custom module to run this post processing code. I can hook into the EndRequest event but at this point, the Session is no longer available.

Edit Specifically what I need to do is modify the value of two specific slots in session state. One is a value type, and one is a reference type. I am also using InProcess Session State Any ideas or suggestions?

Answers


All though Response.End (will suggest to use HttpApplication.CompleteRequest instead) short-circuits application events, session state module will still persists the session state on end request. Whenever session state module persist the session state, it will remove the session bag from the context.

So one of the hack way of doing it could be to have flag in your module. Set the flag if PostRequestHandlerExecute is fired. Handle EndRequest and if flag is not set then go for session state manipulation. In order to get the session state, clear all modules in your web.config and put your module before session state module (going by general observation that modules receive app events in the order of registration).

Cleaner way would be to have your own session state store provider - so that you can expose methods to get the session state bag based on the session id which will be used in your module to manipulate the session slots.


Need Your Help

Programmatically determine background of image (logos, etc) and make transparent?

vb.net image background transparency watermark

I'm attempting to write a solution so that my user's can "watermark" their Images with their Company Logo. I've got the actual watermarking part done and working so now I'm creating the "upload logo"

How to adjust the height and bold the text of the tab's in android programmatically?

java android tabs

Can someone tell me how should i adjust the height of my three tabs's diagrammatically rather than in xml because my picture overlaps the wording therefore i had to adjust my tab's slightly longer ...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.