如何在ASP.NET MVC声明全局变量?
解决方案 公共静态类GlobalVariables
{
//只读变量
公共静态字符串富
{
得到
{
返回富;
}
}
//读写变量
公共静态字符串酒吧
{
得到
{
返回HttpContext.Current.Application [条]作为串;
}
组
{
HttpContext.Current.Application [条] =价值;
}
}
}
How do you declare global variables in ASP.NET MVC?
解决方案public static class GlobalVariables
{
// readonly variable
public static string Foo
{
get
{
return "foo";
}
}
// read-write variable
public static string Bar
{
get
{
return HttpContext.Current.Application["Bar"] as string;
}
set
{
HttpContext.Current.Application["Bar"] = value;
}
}
}