Dear buddy
If anyone explain HttpContext , how pass value in cache give one example with source code
HttpContext with example
3 Answers
Know the answer? Post it. Somebody with the same question will find it here.
Know the answer? Post it. Somebody with the same question will find it here.
Answer a question in the forums and earn +20 SHARP for every answer.
See unanswered questions
DevSocialUpcoming · 3rd editionAI Agents ConferenceDec 1–3, 2026Live onlineFree to attend5days leftRegister
Gohil JayendrasinhRank #490 · 5K reputationPosted Feb 21, 2012, 3:13 AM EST
Pramod Kumar NandagiriRank #6,963 · 252 reputationPosted Feb 21, 2012, 3:30 AM EST
string abc = HttpContext.Current.Cache["key"].ToString();
Jignesh TrivediRank #16 · 50.3K reputationPosted Feb 21, 2012, 5:54 PM EST
HttpContext.Current is available to all pages, but not necessarily to all threads. If you try to use it inside a background thread, ThreadPool delegate, async call (using an ASP.NET Async page), etc., you'll end up with a NullReferenceException.
If you need to get access to the cache from library classes, i.e. classes that don't have knowledge of the current request, you should use HttpRuntime.Cache instead. This is more reliable because it doesn't depend on an HttpContext.
To ADD in to cache.
HttpContext.Current.Cache.Add("hi", x, null, DateTime.MaxValue,
Cache.NoSlidingExpiration,
CacheItemPriority.Normal, null);
Retrieve from cache.
HttpRuntime.Cache[key]
please refer,
http://msdn.microsoft.com/en-us/library/system.web.httpcontext.cache.aspx
http://weblogs.asp.net/pjohnson/archive/2006/02/06/httpruntime-cache-vs-httpcontext-current-cache.aspx
hope this help.