c#和.net的全局变量 [英] global variable for both c# and .net

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

问题描述

你好,





在我的网站上有主页在.net页面,第二个是在C#所以< br $>


i想创建全局变量以从.net页面获取数据到c#页面。





谢谢,

hi there,


in my website there is home page is in .net page and second one is in C# so

i want to create global variable to fetch data from .net page to c# page.


thanks,

推荐答案

首先,正式来说,这不是一个问题,而是一个无效的请求。原因如下:.NET中没有全局变量这样的概念,因此在ASP.NET中,这是框架的最佳功能之一。在功能意义上,最接近的是类或结构的公共静态字段的概念,它不同并且也不应该被推荐。



但是,非正式地说,如果你以其他方式制定它,你的问题就有意义了。由于这是ASP.NET,因此问题在于HTTP协议的无状态特性以及保持状态的需要。请参阅:

http://en.wikipedia.org/wiki/Stateless_protocol [< a href =http://en.wikipedia.org/wiki/Stateless_protocoltarget =_ blanktitle =New Window> ^ ],

http://en.wikipedia.org/wiki/Http#HTTP_session_state [ ^ ]。



你可以从这里开始: http://msdn.microsoft.com/en-us/library/ms178581.aspx [<一个href =http://msdn.microsoft.com/en-us/library/ms178581.aspxtarget =_ blanktitle =New Window> ^ ]。



-SA
First of all, formally, this is not a question, but is an invalid request. Here is why: there is not such concept as "global variable" in .NET, and, hence, in ASP.NET, and this is one of the best features of the framework. The closest, in a functional sense, would be the concept of "public static field of a class or a structure", which is not the same and also should not be recommended.

Informally, however, your problem would make sense if you formulated it in some other way. As this is ASP.NET, the problem is the stateless nature of HTTP protocol and a need to preserve the state. Please see:
http://en.wikipedia.org/wiki/Stateless_protocol[^],
http://en.wikipedia.org/wiki/Http#HTTP_session_state[^].

You can start here: http://msdn.microsoft.com/en-us/library/ms178581.aspx[^].

—SA


使用会话状态来存储您可能需要为整个会话托管的日期。
Use session state to store date that you may need to host for an entire session.


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

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