简体   繁体   中英

Session vs static Property in c#

I wanted to use some data from one page to another. General solution is to use Session (most of recommends). My boss don't like sessions and he suggested me to do same work by using C# Property in common class as below

public static long parentId { get; set; }

and set it one one page as

Common.parentId = "any value";

and use it on other page like

string anyVariable = Common.parentId

and it worked. We get rid of session expiration as well. But why most of people recommend session. Is property another state management thing?

If you are going to store some data using simple static property you must understand that it will be shared among all your users. Sessions are not for this. But I don't see any reasons not to use sessions if you want to store user data somewhere.

In my project it is very convenient, especially when we use SQL-server to store sessions - we can update our website without any losing users' sessions data. You can check all possible ways to hanle sessions for example herehttp://msdn.microsoft.com/en-us/library/75x4ha6s(v=vs.100).aspx

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM