ASP.NET MVC C#的全局变量 [英] ASP.NET MVC C# global variable

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

问题描述

我需要保存的价值为我所有的网站,有没有办法将其保存在一个全局变量在服务器端一样的ViewData的为例还是更将其保存在cookie?

I need to save a value for all my website, is there a way to save it in a global variable in the server side like ViewData for exemple or is it better to save it in a cookie ?

此数据是使用一个DropDownList设置,并在控制器捕获。

This data is set using a dropdownlist and catched in the controller.

感谢。

推荐答案

也可以使用会话是这样的:

Can also use session like this:

Session["MyKey"] = "MyValue";

和检索是这样的:

var myVar = (string)Session["MyKey"];

如果这是每个用户的价值。

if that's per user value.

希望这是帮助。

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

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