ASP.NET MVC全局变量全局变量、ASP、NET、MVC

2023-09-02 10:24:31 作者:Fishbone(鱼刺)

如何在ASP.NET MVC声明全局变量?

解决方案

 公共静态类GlobalVariables
{
    //只读变量
    公共静态字符串富
    {
        得到
        {
            返回富;
        }
    }

    //读写变量
    公共静态字符串酒吧
    {
        得到
        {
            返回HttpContext.Current.Application [条]作为串;
        }
        组
        {
            HttpContext.Current.Application [条] =价值;
        }
    }
}
 

How do you declare global variables in ASP.NET MVC?

解决方案 Microsoft ASP.NET MVC 3.0 ASP.NET MVC 3下载 官方安装包

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;
        }
    }
}

 
精彩推荐
图片推荐