I am getting a serialization error trying to use Session State Server instead开发者_开发问答 of InProd. However, I can't figure out what is causing the error in session. I was given some code to add to the page to loop through the session object and figure out if each item in it is serializable. My problem is I don't know where to place the code in the ASP.NET page. In tracing through the code, the error just appears after steping through objects outside of the page and not when setting session. There must be some place that I can place the code on the page that is after all session objects are set but before the page will error. Where would that be?
You could put it in pageload, set a breakpoint and then step through the deserializing code until it barfs -- that will tell you which object isn't serializable yet and is blocking the transiton to using SQL for sessions. It's hard to tell without the source code you were given to test for serializable.
It might help to think through what you're trying to do here. Because SQL State Server requires objects to be Serializable where InProc does not, any object you put into Session needs to be Serializable.
So you want to validate that any objects you store in Session are Serializable, or, as the other answerer said, figure out which object isn't Serializable and causing the problems.
It's pretty easy to test whether an object can be Serialized. You can use the sample code you were given or just create a unit test (or test in a pageload for your app if that's easier) that tests the various types you store in session as serializable.
The answer to this question is to place the code in the SaveStateComplete event handler.
精彩评论