ASP.NET MVC全局变量 [英] ASP.NET MVC Global Variables

查看:3264
本文介绍了ASP.NET MVC全局变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在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;
        }
    }
}

这篇关于ASP.NET MVC全局变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆