【发布时间】:2016-03-10 21:14:01
【问题描述】:
我在 MVC 4 ASP.NET 项目的 Settings 类中遇到了 Object Reference not set to an instance 错误,该类获取了我的当前会话详细信息。每次我浏览一个页面时,该变量都会抛出 NullReferenceException,并且无法理解为什么,因为它以前可以完美运行,没有任何问题。
namespace TracerCRM.Web
{
public class Settings
{
public static Settings Current
{
get
{
Settings s = HttpContext.Current.Session["Settings"] as Settings;
if (s == null)
{
s = new Settings();
HttpContext.Current.Session["Settings"] = s;
}
return s;
}
}
}
}
我尝试了以下我在研究过程中遇到的事情:
1:"HttpContext.Current.Session" vs Global.asax "this.Session"
3:The Session object is null in ASP.NET MVC 4 webapplication once deployed to IIS 7 (W 2008 R2)
4:Log a user off when ASP.NET MVC Session expires
5:Login Session lost sometimes when redirect to action in asp.net mvc 3
以上都不适合我。
【问题讨论】:
-
当您说“因为它之前工作完美而没有任何问题”时,“它正在工作”部分是在将您的设置逻辑包装到
Settings类之前? -
不,我不得不开始在项目中进行新的开发,DayPilot Calendar Control,从那时起,我就遇到了这个问题。
-
@Hennie 检查我的答案并告诉我是否有不清楚的地方。
-
@mybirthname,我试过了,还是一样的错误
标签: c# asp.net asp.net-mvc asp.net-mvc-4 session