Tuesday, 15 September 2015

caching - ASP.Net HttpContext Cache-- why do I read Null when someone else says ""? -


I have a colleague who has written the following line in the page load method in an aspx page:

  myDataSet = (Dataset) HttpContext.Current.Cache ["Dataset"];  

The first time I pressed the page HttpContext.Current.Cache ["dataset"] reads tap when it does, the value "" ( String.Empty ) and it is an exception.

We are running both ASP.NET 2.0 on our development machines, it has cleared our browser cache and runs an iisreset, yet still read that thing for the first time when it Hits the page. What can we do to explain this discrepancy to someone?

Try this instead, you should avoid killing at least exception:

  myDataSet = HttpContext.Current.Cache ["Dataset"] as DataSet;  

No comments:

Post a Comment