Session status in ASP. NET: ireadonlysessionstate, ihttpsessionstate, and irequiressessionstate

Source: Internet
Author: User

ASP. NET session status allows youProgramWhen you navigate between different ASP. NET pages, you can store and retrieve values. HTTP

Is a stateless protocol, which means that the Web server processes every HTTP request on the page as an unrelated request. By default, the server does not retain

Any information about the value of the variable used during a request. Therefore, if you want to generate Web applications that need to maintain cross-Request status information (such

Applications such as vehicle and data scrolling may be very difficult. ASP. NET session Status identifies a request received from the same browser within a limited period of time

Sessions, and the variable value is retained during the session duration.

By default, all ASP. NET applications enable the ASP. NET session status. Use Attribute (store the session variable value as a name

Set of indexes) allows you to conveniently set and retrieve ASP. NET session state variables. For exampleCodeExample: Create a session variableFirstnameAndLastname

To indicate the user's name and surname, and then set them Control.

Session ["firstname"] = firstnametextbox. text;
Session ["lastname"] = lastnametextbox. text;

 

ASP. net stores session information in the memory space of ASP. NET applications by default. You can use an independent service to store session information

After the ASP. NET application is started, session information is retained; or session information is stored in SQL server so that session information can be used by multiple Web servers in the Network

The session information is retained after the ASP. NET application is restarted, or the session information is stored in the Custom Data storage area. ASP. NET session Status Mode

There are several types

 

ASP. NET session Status supports several storage options for session data. Each option is composed A value identifier in the enumeration. The following list

Describes the available session Status modes:

    • Mode, which stores the session Status in the memory of the Web server. This is the default setting.

    • Mode, which stores the session status in a separate process named ASP. NET status service. This ensures that the Web application is restarted.

    • The session status is retained during the program, and the session status can be used by multiple Web servers in the network farm.

    • The session state is stored in an SQL Server database. This ensures that the session status is retained when the web application is restarted,

    • The session status can be used on multiple Web servers in the network farm.

    • Mode, which allows you to specify a custom storage provider.

    • Mode, which disables the session status.

In the Web. config file of the application ElementModeAssign a propertySessionstatemodeEnumeration value, which can be specified

The mode used by ASP. NET session status. BesidesInprocAndOffAdditional parameters are required for other modes, such as the connection string discussed later in this topic.

Value. Access Attribute Value to view the status of the selected session.

 

For details, see:

MS-help: // msdn/0bb0a3a3-440f-4c47-a0c5-b08b9b591bb4.htm

 

After learning about session management in Asp.net, let's take a look at the topics to be discussed today:

Ireadonlysessionstate, ihttpsessionstate, irequiressessionstate

Ihttpsessionstate Define the Protocol to implement custom session Status containers.
Ireadonlysessionstate Specify that the target HTTP handler only requires read access to the session status value. This is a tag interface and there is no way.
Irequiressessionstate Specify the target HTTP handler to have read and write access to the session status value. This is a tag interface and there is no way.

 

We often need to access or set the values in the session in the custom processing program (ashx). For example, when calling the custom processing program through Ajax in the shopping cart program, we may

Select different items based on different user levels to achieve different discounts. In this custom processing program, you need to read the user information in the session and read and write the user information in the shopping cart.

And so on. If it is not identifiedIreadonlysessionstate, OrIrequiressessionstateInterface, we cannot access the information we need.

Therefore, we can see the importance of these identity interfaces.

 

If you only need to read the session status value in your custom programIreadonlysessionstateYou can.

If you need to have read and write permissions on the session Status in your custom programIrequiressessionstate

If these two interfaces cannot meet your requirementsIhttpsessionstate interface.Refer to: msdn

 

 

Related Article

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.