0

I have ASP.NET web site using “inproc” as session management in single server. Now, I need to put the web site to two servers in web farm (behind load-balanced environment). We learned that “inproc” mode would not work anymore in the web farm environment. So, I am looking at the option to switch from “inproc” to SQL server mode. Also, I learned that it is not just matter of updating the web.config (Of course, creating SQL database). Since, I am saving datatable, user defined classes, List,… to the session variables. I understand that I have to make user defined classes as serializable (just put [Serializable] in the class) and .NET will take care the rest (I don’t have to put a code explicitly to handle this).

Is this correct? And, what about other “special” type such as DataTable, List, how do I make them seraizable?

Thanks.

1
  • All session data have to be serializable anyway, either inproc or sessionstate or any other mode. Commented Jul 4, 2011 at 13:41

3 Answers 3

1

This is basically correct, although the work behind making the classes, testing everything etc is not trivial. Everything you need ot store in session needs to be serialised, so for "special" data types, you will need to produce serialised versions of them. You might want to look at why you are saving data tables into your session state? I would suggest you have a very good look at what you are doing, and save only the minimal amount there - keys not entire objects.

My current client is using a SQL session with a lot of large objects, and it runs slowly, because there is a need to serialise and deserialise these large objects, as well as writing and reading form the DB.

And you might sometime in this realise why people say that session variables are a bad idea. Scaleability is the big issue, both from the amount of work you have to do now and the size issues of your sql session store.

ETA: As others have said, the serialiseable issue is the same for whatever type of session state.

Sign up to request clarification or add additional context in comments.

4 Comments

+1 for advice on serializing whole objects - I was too lazy to add it to my answer. @tony - That advice may serve you very well considering one of your other questions on here
Only reason why I am storing the DataTable in session is to retrieve it back upon postback so that I dont have to run the qurey again to get it. I am not sure if there is another way I can retrieve it without saving it to the session.
If you have to do it, do so, but bear in mind that it will be very inefficient, and you may find that it is quicker to redo the query. Or to save the data in a temporary table and retrieve it.
So, it looks like from AD.net and Johan's comments, I don’t have to explicitly serialize/ deserialize for predefined types (DataDatable, List,...), and I need to mark the user defined classes as seriaziable?
1

I also had to switch an application from InProc to SqlSessionState

  • for the DataTable, it is already Serializable1.
  • for the List<T>, it is serializable if and only if T is Serializable.

Most .NET simple types are Serializable. However, if you declare and use your own classes, you must declare them Serializable in order to store them in session.

tl;dr; Switch your Sessionstate to SqlServer and serialize till it works.

The second test is to ensure the same encryption and decryption context for your two servers. Please read http://msdn.microsoft.com/en-us/library/w8h3skw9%28v=vs.71%29.aspx and ensure both servers use the same key.

Comments

0

To reinforce @AD.Net's comment, if you were able to store the objects using inProc mode, there should be no problem storing using the other modes with regards to serialization.

For objects like datatable, you'll find that according to MSDN these classes are already marked as serializable under the hood.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.