.NET Answers

ASP.NET, HTML, CSS, Visual Studio, CSharp, VB.NET and other programming items of interest.
Subscribe
  • Home
  • About Me
  • Advertising
  • Click Here to Ask a question
    • Privacy Policy
  • Site Map

ASP.NET Three Tiered w/ Client Side Data

August 18, 2008 By: Dave

G07L0077 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.

If you're new here, you may want to subscribe to my RSS feed. Thanks for visiting!

Related Post

  • Tracking Down Performance Issues in ASP.NET
  • Is LINQ Multi Layered?
  • jQuery – Date Picker
Bookmark to:

Add to Del.icio.us Add to digg Add to DotNetKicks Add to DZone Add to Facebook Add to Slashdot Add to Stumble Upon Add to Technorati
Hide Sites
Tags: asp.net, httpcontext, multi-layered, Three Tiered

One Response to “ ASP.NET Three Tiered w/ Client Side Data ”

  1. # 1 Dew Drop - August 18, 2008 | Alvin Ashcraft's Morning Dew Says:
    August 18th, 2008 at 8:53 am

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

← Microsoft’s Biggest Mistake with ASP.NET
DotNetNuke – Make Your Module Searchable →
  • Search

  • Subscribe

    U COMMENT
    I FOLLOW

    Subscribe in a reader

    OR

    Subscribe via e-mail

    Enter your email address: 

    Delivered by FeedBurner

     

  • Follow Me

    • Twitter
    • FaceBook
    • Digg
    • StumbleUpon
    • Propeller
    • Delicious
    • Plaxo

     

  • Recent Posts

    • ASUS Eee PC 1005HA-PU1X-BK Black Netbook
    • jQuery – Date Picker
    • Using VB.NET From CSharp
    • iTextSharp – Adding Images
    • Hungarian Notation – Use What Works, Spit Out The Bones
    • Pre Order Windows 7
    • jQuery Dialog – With Validation Controls
    • iTextSharp – The easy way
    • Structure of my ASP.NET Web Applications
    • 35% Off Accronis True Image 2009 Home
    • VB.NET Hide Module Name
    • ASP.NET/VB.NET – Video Training
    • Does jQuery Make Us Lazy?
    • PDFs Using iTextSharp
    • Programming SEO – Ping



  • Advertise on this site through Lake Quincy Media
  • DotNetNuke Sponsor

     

    Most Valuable Blogger
  • Sponsor

  • Categories

    • Advanced CSharp
    • Advanced VB.NET
    • ASP.NET MVC
    • Did you know
    • DotNetNuke – Module Development
    • DotNetNuke – Skinning
    • internationalization
    • iTextSharp
    • jQuery
    • none
    • Seach Engine Optimization
    • Silverlight
    • SQL For Programmers
    • Twitter
    • winforms
  • Cloud

    .net ajax architecture asp.net book books containers csharp css dal dataset datasets dotnetnuke events gridview images internationalization internet explorer javascript jQuery json linq listview modules ms-sql MVC objectdatasource programming reflection seo Silverlight skinning sql testing tsql tutorial Twitter twitterizer vb.net video view Vista visual studio webservice WordPress
  • Archives

    • July 2009
    • June 2009
    • May 2009
    • April 2009
    • March 2009
    • February 2009
    • January 2009
    • December 2008
    • November 2008
    • October 2008
    • September 2008
    • August 2008
    • July 2008
    • June 2008
    • May 2008
    • April 2008
    • March 2008
    • February 2008
    • January 2008
    • December 2007
    • November 2007
    • October 2007
  • Meta

    • Log in
    • Entries RSS
    • Comments RSS
    • WordPress.org
    • Privacy Policy
  • Calendar

    August 2008
    S M T W T F S
    « Jul   Sep »
     12
    3456789
    10111213141516
    17181920212223
    24252627282930
    31  
  • Blogroll

    • Alvin Ashcraft’s Morning Dew
    • ASP.NET Consulting
    • Life Hacker
    • Remember Anything
    • The Price of Their Toys
    • Uncategorized Thought


.NET Answers © 2007 - 2008 All Rights Reserved.
Entries and Comments.