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:
9W X 36H 3 Lt Blush/Craftsman Tiered ShowerColor Theme: Craftsman collection: Deco Art Glass Contemporary custom Crafted in Yorkville, New York. Please allow 28 Days prior to shipment.PHYSICAL DIMENSIONS TOTAL:36H. SHADE: 29.5Hx18W BULB: MEDx3 MAX WATT: 60x3
Silver 3 Tiered ChandelierHang it for an ultra-elegant look on a budget. Our chandelier is made of thousands of carefully detailed metallic mylar strands with chrome hanging chains.They are pre-assembled and ready to hang! 3 high, 32" diameter.
Prevail Male Guards Extra Absorbency, Size: 6" x 13" - 14 Ea/Pack, 9 PackPrevail Male Guards are most appropriate for light urinary incontinence. Dual core construction includes a multi-layered absorbent system and a blue, high loft transfer layer. A cup like shape and full adhesive strip provides protection specifically designed for men. Size: 6 x 13 inches.










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