There is a few options to used if you want to stored object on the server-side. Some of the common techniques people used are including Session, Cache, Application. There's a different between each of the techniques.Obviously Items does not gain a lot of attention from developer. Mike Duncan has posted 3 hot uses for HttpContext.Current.Items that might change the way developers look at it. So what it is? What so special about it? Where can I used it? Taken from MSDN site:
Notice the word HTTP request. It can be used to stored object in a single HTTP request to achieve a singleton in ASP.NET (only in single request). Ah ha. Simple idea how we can take advantage of this is by creating a class that can be used to stored key and object in a single HTTP request. This idea can be expand to create a more reusable framework for managing context. Another advantage of this property is that you can add object in all http request pipeline. Meaning you can share data between httpmodules and httphandlers implementation. One example use of HttpContext.Items is to store page setting when visitor request for the page.
1: public static PageSettings GetPageSetting()
3: if (HttpContext.Current == null) return null;
5: PageSettings currentPage = HttpContext.Current.Items["CurrentPage"] as PageSettings;
6: if (currentPage == null)
8: currentPage = LoadCurrentPage();
9: if (currentPage != null)
10: HttpContext.Current.Items["CurrentPage"] = currentPage;
12: return currentPage;
There's lack of documentation about HttpContext.Items from Microsoft. Here's are some of the resources I found:
- HttpContext.Items - a Per-Request Cache Store
- 10 Tips for Writing High-Performance Web Applications
- ASP.Net's Data Storage Objects
- The HttpContext Items Collection
Until next time.
This is my second attempt to write on a public on what I've found interesting to be shared and I hope it can established a series of posting. From The Pragmatic Programmer's book tip #23: Always Use Source Code Control. For me, using source control is not just for tracking purpose. There's a lot of free source code project hosting available publicly on the Internet. One of the reason I've installed TortoiseSVN on my machine is to let me sync down those open source codes from public hosting such as code.google.com, codeplex.com or sourceforge.net (this require CVS). For code.google.com you can use TortoiseSVN directly because it was hosted using Subversion server. For codeplex.com, Microsoft's open source project hosting web site, the source code was hosted using Microsoft's proprietary Team Foundation Server (TFS). You can you either use TortoiseSVN or CodePlex Client to access the code repository. I prefer to use TortoiseSVN since I already used it to access the code from other SVN server. This is possible with SvnBridge, a tool that converts the call made by subversion client to the API supported by TFS. The developer's planet is lucky enough to have TFS SDK available, this will allow other tool to talk to TFS. To get it running on your local machine is pretty easy and no harm.It's a mandatory tools to be installed on your machine since a few cool projects hosted there:
Now lots of source codes to be sync down.
- ASP.NET MVC - This is the first on my list. The page is shared with ASP.NET preview and Dynamic Data as well.
- MvcContrib - Contrib project for ASP.NET MVC Framework.
- S#arp Architecture - ASP.NET MVC with NHibernate.
- Patterns & Practices - Enterprise Library is one of them. You also can find other P&P code here such as Smart Client Guidance or Unity Application Block
- Ajax Control Toolkit - grab this if you want to see how they develop the controls.