静态属性如何在asp.net环境中工作? [英] How do static properties work in an asp.net environment?

查看:64
本文介绍了静态属性如何在asp.net环境中工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如果我有一个带有静态属性的类,该类是在用户加载特定页面时设置的,那么该静态值对于该用户会话是唯一的吗?

If I had a class with a static property that is set when a user loads a particular page, is that static value unique to that users session?

换句话说,如果第二个用户然后加载页面并设置静态属性,那么每个用户将具有不同的值,还是都将使用第二个用户的值?

In other words, if a second user then loads the page and sets the static property, will each user have a distinct value, or will both use the second users value?

推荐答案

统计信息对于应用程序域是唯一的,该应用程序域的所有用户将为每个静态属性共享相同的值.当您看到静态"一词时,请考虑只会有一个实例".该实例可以持续多长时间是一个单独的问题,但简短的答案是它是可变的.

Statics are unique to the application domain, all users of that application domain will share the same value for each static property. When you see the word static, think "there will only be one instance of this." How long that instance lasts is a separate question, but the short answer is that it is variable.

如果要存储特定于用户的值,请查看会话状态.

If you want to store values specific to the user look into Session State.

这篇关于静态属性如何在asp.net环境中工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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