Search code examples
asp.net.netsessioniissession-state

Using ASP.NET State Service for session sometimes give scrambled pages


Doing my first steps with the ASP.NET out-of-process session management by using the ASP.NET State Service and activating it via

<sessionState
    mode="StateServer"
    stateConnectionString="tcpip=127.0.0.1:42424"
    cookieless="false"
    timeout="600" />

inside my web.config file, I sometimes get pages like these:

enter image description here

When I hit F5 in the browser to refresh, different random characters appear.

Somehow when restarting the ASP.NET State Service and/or restarting IIS, I manage to make the page look correct, again.

This happens both on my local IIS Express as well as on IIS7 on a production server.

My question:

Does anybody have a clue, what is going on here?

Update 1:

I've found some entries in the event log that a type is not marked as serializable. I'll now try to get rid of these messages, maybe they are the reason for the garbage?


Solution

  • To answer my own question:

    The garbage pages as of my screenshot always came together with a SerializationException in the Windows Event Log.

    I tried to run it in the debugger but it did not halt on the exception.

    So my only chance was to make one class a time serializable (by changing some code and adding the [Serializable] attribute to the class), then run the ASP.NET application again, until another of the garbage pages occured again and then look into the event log and repeat the steps...

    As soon as all required session-stored objects were serializable, the garbage disappeared.

    (BTW: when browsing the erroneous pages with Internet Explorer instead of Google Chrome, no garbage appeared but instead Internet Explorer tried to download and save the page instead of showing it)

    Maybe this will be of some help for someone, some day.