This is a discussion on whats the Use of Storing Sessions external to InProc? within the Microsoft .NET forums, part of the Programming Talk category; Hai, Can any one clarify whats the difference in storing Sessions externally that storing in Inproc. whats the difference between ...
|
|||||||
| Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
|
|||
|
whats the Use of Storing Sessions external to InProc?
Hai,
Can any one clarify whats the difference in storing Sessions externally that storing in Inproc. whats the difference between SqlServer and StateServer and in what cases we use them? |
|
|||
|
difference between SqlServer and StateServer
StateServer
StateServer is a service which is off by default. You can enable it by going into "Administration" --> "Services" and right-clicking on "ASP.NET State Service" (go to Properties and select "automatic" if you want it to start when Windows starts). When your sessionState is in StateServer, sessions aren't stored in the ASP.NET worker-process, which avoids the worker process recycle problem. Additionally, two or more separate web servers can access a single StateServer, meaning session state will automatically be shared across a web farm. There are two very important things to keep in mind when using StateServer. Firstly, it isn't as fast as having the data stored directly in the ASP.NET worker process. This can be easily resolved by smarty using the HttpCache class. Secondly, data stored in the StateServer must be serializable. Strings, ints and most built-in types are mostly all automatically serializable. Custom classes can typically be marked by the System.SerializableAttribute attribute: [Serializable()] public class User { private int userId; private string userName; private UserStatus status; public int UserId {get { return userId; } set { userId = value; }} public string UserName {get { return userName; }set { userName = value; }} public UserStatus Status {get { return status; }set { status = value; }} public enum UserStatus { Invalid = 0, Valid = 1 } } To use StateServer, you must specify both the SessionState mode, as well as the address of the StateServer via stateConnectionString. StateServer runs on port 42424 by default, so the example below connects to the state server on the local machine. SQL Server Using SQL Server is much like using StateServer. Both require data to be serializable, both are overall slower (but won't cause the entire app to have performance issues), and both can be accessed by multiple web servers. The difference between the two is, well obviously, one uses the StateServer service while the other uses SQL Server. This has pretty wide implications. By storing your sessions in SQL Server, you can take advantage of multiple databases, load balancing, and fault-tolerance. You also have to pay big money for it. Enabling SQL Server is much like StateServer: set the mode to SQLServer and specify the connection via the sqlConnectionString attribute: Additionally, you must run a script to create the database. This script is located in system drive\WINNT\Microsoft.NET\Framework\version\InstallSqlState.sql, for example: C:\WINDOWS\Microsoft.NET\Framework\v1.1.4322\InstallSqlState.sql on my computer (Windows instead of WinNT because I'm using XP). Simply run it, and you're ready to go. |