Asp. A problem and solution of net storage state

Source: Internet
Author: User

Typically, ASP. NET storage session state is available in three ways--inproc, StateServer, and SQL Server. The most commonly used is the first, in which case a syntax like this can be used to store session state: session["Key" = val. Where Val can make any type of object.

However, if you use StateServer or SQL Server, the type of Val is required to be a serializable type, because the ASP.net application requires serialization of the object when the data is exchanged between state servers. If Val is not serializable (has a private domain/attribute and does not specify a custom serialization attribute), the following exception occurs at run time:

Server error in '/' Application.

--------------------------------------------------------------------------------

Unable to serialize session state. In either "StateServer" or "SQL Server" mode, ASP.net will serialize the session-state object, so objects that cannot be serialized or MARSHALBYREF objects are not allowed. The same restriction applies if the custom session state store performs a similar serialization in custom mode.

There are several ways to solve this problem:

1 use basic types of objects to store data as much as possible

2 Custom types use public domain/attribute only

3 Implementing serialization attributes for custom types

......

The advantages and disadvantages of several methods are not explained. I used the first kind of slack.

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.