Asp. NET state management four (staging state httpcontext.items)

Source: Internet
Author: User
Tags httpcontext

Asp. NET provides a class System.Web.HttpContext, which is used to represent the context, which has a property items

The staging state is the use of the Httpcontext.items property to hold the data

The explanation for the Httpcontext.items property in MSDN is this: Gets the key value that can be used to organize and share data between IHttpModule and IHttpHandler during an HTTP request

The Httpcontext.items attribute can hold any type of data, regardless of what data is stored in this attribute, will be automatically purged after the request processing ends, this is the staging state, the data storage time is very short.

//For example://we have a page a.aspx, there is a button id:submit, click the button to turn the page b.aspx page Public voidSubmit_click (Object sender, EventArgs E) {SqlConnection myconnection=NewSqlConnection ("server= (local) netsdk;database=pubs; Trusted_connection=yes"); SqlDataAdapter mycommand=NewSqlDataAdapter ("SELECT * from Authors", MyConnection); DataSet DS=NewDataSet (); Mycommand.fill (DS,"Authors"); //put the data into the stagingcontext.items["MyData"] =ds;    Server.Transfer (b.aspx); }//On the b.aspx page Public voidPage_Load (Object sender, EventArgs E) {if(!IsPostBack) {    //Get Staging DataDataSet ds= (DataSet) context.items["MyData"]; //Other data Processes    }  }

Asp. NET state management four (staging state httpcontext.items)

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.