tags:

views:

196

answers:

2
A: 

Should you be using HttpContext.Cache instead of HttpRuntime.Cache ?

Dan Diplo
Yes - that is what I had originally but I ran into the same problem.
the first one is a shortcut to the 2nd.
+1  A: 
pcs.values["txtName"]

That's null and it's already gone from Cache when you're trying to receive it. Your code seems to cache some per-request data obtained from users' input and there's nothing to guaranty the availability of that data in your cache.

Every cache access should be prepared to fetch the data from the data source in case of a miss, so, in your case I would use the user's session (although I'm not aware of your architecture, how many servers...) Using the user's session would persist that data for the life of the appdomain or the session itself (whichever ends first), so you should also be prepared to query it again in case of a miss / timeout / appdomain shutdown.

I'm populating the cache on startup:<code> if (Request["txtUserName"] != null) { userName = Request["txtUserName"]; // Populate the cache with the initial form values from PCS. pcs = new globals(Request.Form); } else { userName = Request.Cookies["PatientDischargeSummary"].Value; pcs = new globals(); Response.Write(userName); }</code>But why would this work in debug mode and not IIS?
And by "startup" I guess you mean your login page. Like I said, if this data is user-specific and you don't need access to it outside of that user's requests code, you should consider storing it in the user's session.