如何存储变量以便整个项目可以访问它?

时间:2014-02-26 06:35:08

标签: asp.net-mvc session static

我有一个很棒的asp.net mvc项目,我希望在我项目的所有部分都有一些变量。 例如:

userid
username
companyid
companyname

我使用session以这种方式存储它:一个名为“Helper”的静态类包含这样的变量:

public static string _username 
{
 get { return HttpContext.Current.Session["_username"].ToString(); } 
 set { if (HttpContext.Current.Session["_username"] == null) { Http    Context.Current.Session.Add("_username", value); } else { HttpContext.Current.Session["_username"] = value; } } 
}

但在某些观看中我的会话无缘无故被删除 你有什么可变项目的最佳建议是什么?

0 个答案:

没有答案
相关问题