我一直在体验一个对象引用未设置为我的MVC 4 ASP.NET项目的Settings类中的对象错误的实例,它获取我的当前会话详细信息.每次我浏览一个页面变量抛出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;
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我尝试过以下在研究中遇到的事情:
1:"HttpContext.Current.Session"vs Global.asax"this.Session"
3:部署到IIS 7后,ASP.NET MVC 4 Web应用程序中的Session对象为空(W 2008 R2)
5:在asp.net mvc 3中重定向到操作时,登录会话有时会丢失
以上都不适合我.