开发者

ASP.NET Session or global variables?

I am开发者_运维技巧 creating an ASP.NET page where I need a couple of variables which hold pathnames and a chosen language etc... Not that many, let's say about 5.

Should I use session variables for this? Atm I'm using public static variables but I'm not sure if this is the right way to do this.

Any thoughts?

Thx


Public static variables are definitely not the correct way of doing this because they will likely be shared between all your users. There's a multitude of ways of storing values. Session state, viewstate, hidden fields, profiles in a database, et cetera... it all depends on what kind of scoping you need for your data.


Based on your description, there is no such thing as global variables, because it seems that each user seems to chose his own language, therefore you need to chose one of Matti Virkkunen's suggestions.

If you really need a thing such as a global variable for all users, you should prefer the Application State over static variables.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜