I have a CustomRequestContext
object that has to be disposed after each request. I create it in Page_Load
and dispose of it in Page_Unload
. The only issue is that in certain circumstances I need to call Server.Transfer
to redirect to another aspx page instead. In this case, the object should not be unloaded until the new page is ready to be unloaded. What is the nicest way of achieving this?
I solved this problem by allowing the object to be owned by one page at a time. If I wanted to relinquish control from a page, I would set it equal to null and then it would not be released in the page's destructor.