ASP.NET Three Tiered w/ Client Side Data
Last week, I created a tool that would allow the user to upload an XML file and have the web site process the file and return a report. All pretty standard stuff until you realize that if you want to use a three-tiered model you have to get the data that the client uploaded into a place that the Business Logic Layer (ObjectDataSource in this case) can see EACH time the object is instantiated.
The obvious solution would have been to store the object into a session variable, but I ruled that out for a number of reasons:
- I use a session server and wasn’t sure the object I was using was serializable and I didn’t want to go to the trouble of making sure it was.
- Session objects hang around much longer than I need.
- There was a cleaner solution available.
One of the little known features of .NET is the HttpContext class, which has a static property named, “Current”. This represents the current round trip as the client requests data from the server. There are a number of objects hanging off of Current. But the one we are interested in today is “Items” which is a collection that works a lot like the Session object. If you only need to store data in a Session object-like thing for the duration of the request and no longer, this is the preferred place to store that information.
What I ended up doing is that I created a Business Logic Layer class that had a property that represented the data that came from the client. Only instead of actually storing the data in a member variable, I stored the data in the HttpContext.Current.Items[] collection.
public MyData Data { get { Object o = HttpContext.Current.Items["myData"]; if (o == null) { o = new MyData(); HttpContext.Current.Items["myData"] = o; } return (MyData)o; } }
Once I had that set up, everything else worked like a normal multi-layered architecture.
Other Related Items:
Mule Deer 3-Tiered 16-Lamp Antler ChandelierFeatures genuine Mule deer antlers. Includes 3 feet of chain. Made in the USA.
LSI Furniture "Stunning" Silver 3-Tiered TV Stand with Support BracketLite Source TV StandYou are currently looking at a Lite Source TV Stand from the Burly family.Finish: SilverHeight: 52 InchesWidth: 47.5 Inches
Minnesota Wild Women's Logo Premier Too Long Sleeve Layered Tissue TeeYou will look your best and feel even better in this Minnesota Wild Women's Logo Premier Too Long Sleeve Layered Tissue Tee from Reebok. Features screen print team logo with sugar glitter on chest.










[...] ASP.NET Three-Tiered w/ Client-Side Data (Dave M. Bush) [...]