Thursday, February 26, 2004

I know what you're thinking...“Too many posts!  He's mad!  He's beating the pants off of Jenkies!“  Well, this one's technical.

If you're like me, you've always been annoyed at the inherent coupling between pages that pass data to each other through a Server.Transfer() call.  I think it leads to poorly designed, tightly-coupled workflows, and tends to lead people to taking shortcuts or breaking the model to make their stuff work.

Until now, I've tried to minimize this issue by giving my base class page a TransferData property typed as an object so every page can use it to pass data.  This has its own problems.  For instance, if you call Server.Transfer twice in the same Request and use Context.Handler to retrieve the transferer (which seems like a hack to me), it's the first page, and there's not a reference to the second page in the call chain.

I now have discovered a nifty little storage location for putting things like this... HttpContext.Items. It's just an IDictionary that stores stuff in the context of the current request.  Since you can always get the current HttpContext with HttpContext.Current (an implementation worth taking a look at with Reflector), you can get to it from anywhere, regardless of whether you have a reference to ANY page.  It works even if you're passing control to or from some handler that's not even a page.

Think of it as the analog to Application state, or Session state, but for the current Request only.  It automatically decouples your pages because they only have to agree on a common key.

UPDATE: I should note that it was my co-worker Casey Marshall who initially brought the property to my attention.  Thanks, Casey

posted on Thursday, February 26, 2004 10:52:25 AM (Pacific Standard Time, UTC-08:00)  #    Comments [0]
Related posts:
LinqToStdf now on CodePlex
Image Slicer for Deep Zoom in Silverlight 2
Silverlight limitations and Constrained Callvirt in IL
What are the generic Delegates in the framework for?
What is System.__Canon and why is it on my stack?
Adding support for .ashx-based views in ASP.net MVC
Tracked by:
"how can i buy phentermine diet pills on line" (how can i buy phentermine diet p... [Trackback]
"pc fan control flow meter" (pc fan control flow meter) [Trackback]
"pioneer dvr hacks" (pioneer dvr hacks) [Trackback]
"knife making grinders" (knife making grinders) [Trackback]
"Free Bondage" (Free Bondage) [Trackback]
"description of adderall" (description of adderall) [Trackback]
"Diflucan AND urinary track infection" (Diflucan AND urinary track infection) [Trackback]
"strong money earning" (strong money earning) [Trackback]
"nota suoneria" (nota suoneria) [Trackback]
"pants wetting accidents" (pants wetting accidents) [Trackback]
"tag heuer 2000 classic" (tag heuer 2000 classic) [Trackback]
"walter rinaldo Toronto" (walter rinaldo Toronto) [Trackback]
"Return of the Jedi Pics" (Return of the Jedi Pics) [Trackback]
"government liquidations" (government liquidations) [Trackback]
"huge cowgirl titties" (huge cowgirl titties) [Trackback]
"Articles on Space" (Articles on Space) [Trackback]
"ice storage bins" (ice storage bins) [Trackback]
"underworld - rez cowgirl mp3" (underworld - rez cowgirl mp3) [Trackback]
"M%26T bank third quarter 2005 earnings release" (M%26T bank third quarter 2005 ... [Trackback]
"san remo 2006" (san remo 2006) [Trackback]
"bass boat ladders" (bass boat ladders) [Trackback]
"sports by brooks" (sports by brooks) [Trackback]
"wac lighting" (wac lighting) [Trackback]
"florida keys fishing charters" (florida keys fishing charters) [Trackback]
"darvocet withdrawal symtym" (darvocet withdrawal symtym) [Trackback]
"adult film industry jobs" (adult film industry jobs) [Trackback]
"direcway vpn" (direcway vpn) [Trackback]
"usb 2.0 drivers" (usb 2.0 drivers) [Trackback]
"codici banche" (codici banche) [Trackback]
"crystal angel figurine" (crystal angel figurine) [Trackback]
"xango cheesecake" (xango cheesecake) [Trackback]
"armored car" (armored car) [Trackback]
"growing pain" (growing pain) [Trackback]
"toms hardware guide" (toms hardware guide) [Trackback]
"2way pager service" (2way pager service) [Trackback]
"school mates" (school mates) [Trackback]
"wildlife biology jobs" (wildlife biology jobs) [Trackback]
Name
E-mail
(will show your gravatar icon)
Home page

Comment (HTML not allowed)  

Enter the code shown (prevents robots):