【发布时间】:2010-11-12 07:34:18
【问题描述】:
全部,
我有一个 ASP.NET(C#),它可以与集成的调试器/Web 服务器一起按预期运行。但是,当我将它移到 IIS 服务器时,它看起来好像没有设置缓存对象。任何人都可以提供任何帮助吗?
这是设置缓存和后续 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);
}
我使用缓存的一个例子:
globals pcs;
protected void Page_Load(object sender, EventArgs e)
{
if (!Page.IsPostBack)
{
pcs = new globals();
lblActiveEditor.Text = pcs.values["txtName"];
}
}
在IIS下产生如下错误:
[NullReferenceException:对象引用未设置为对象的实例。] Demographics.ascx.cs:23 中的 navigationtest.Demographics.Page_Load(Object sender, EventArgs e) System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp,对象 o,对象 t,EventArgs e)+15 System.Web.Util.CalliEventHandlerDelegateProxy.Callback(对象发送者,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
有什么想法吗?
【问题讨论】: