Dear buddy
If anyone explain HttpContext , how pass value in cache give one example with source code
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
Jignesh TrivediPosted Feb 21, 2012, 10:54 PM
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.
Pramod Kumar NandagiriPosted Feb 21, 2012, 8:30 AM
string abc = HttpContext.Current.Cache["key"].ToString();
Gohil JayendrasinhPosted Feb 21, 2012, 8:13 AM