All,
I have an ASP.NET(C#) that functions as expected with the integrated debugger/web server. However when I move it over to a IIS server it appears as though the cache object is not being set. Can anyone offer any help?
Here is the class that sets the cache and subsequent cookie.
class globals
{
public NameValueCollection values;
private static string m_visitNumber ="";
public globals()
{
string userName = HttpContext.Current.Request.Cookies["PatientDischargeSummary"].Value;
values = HttpContext.Current.Cache[userName] as NameValueCollection;
}
public globals(NameValueCollection form)
{
// Copy the form values.
values = new NameValueCollection();
values.Add("txtCR", form["txtCR"]);
values.Add("txtName", form["txtName"]);
// Add the values to the cache.
//HttpContext.Current.Cache.Insert(form["txtUserName"], values, null, System.Web.Caching.Cache.NoSlidingExpiration, TimeSpan.FromMinutes(5));
HttpRuntime.Cache.Insert(form["txtUserName"], values, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
//HttpContext.Current.Cache.Insert(form["txtUserName"], values, null, DateTime.Now.AddMinutes(5), System.Web.Caching.Cache.NoSlidingExpiration);
// Add the username to the cookies.
HttpCookie cookie = new HttpCookie("PatientDischargeSummary", form["txtUserName"]);
cookie.Expires = DateTime.Now.AddMinutes(30);
cookie.HttpOnly = true;
HttpContext.Current.Response.Cookies.Add(cookie);
}
An example of me using the cache:
globals pcs;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
pcs = new globals();
lblActiveEditor.Text = pcs.values["txtName"];
}
}
Generate the following error under IIS:
[NullReferenceException: Object reference not set to an instance of an object.] navigationtest.Demographics.Page_Load(Object sender, EventArgs e) in Demographics.ascx.cs:23 System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +34 System.Web.UI.Control.OnLoad(EventArgs e) +99 System.Web.UI.Control.LoadRecursive() +47 System.Web.UI.Control.LoadRecursive() +131 System.Web.UI.Control.LoadRecursive() +131 System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +1061
Any thoughts?