The difference between HttpContext.Current.Session and Session

Source: Internet
Author: User

A session usually refers to an action from the beginning to the end of an action.

For example "call", usually "1." Pick up the phone--2. Dial the other number--3. The other side--4. Hang up the machine. These four steps form a basic session from completion to the end, and any break in the middle will cause the session to fail.

In the browser, the session is mainly through the connection, "open shopping-click on the connection Select items-Add to the shopping cart-checkout" formed a session, without the use of cookies, any break in the middle of the session will fail.

All, you use the browser to open 2 pages, in a page to assign value, in another browser value, is not access. Values can be taken only in one browser via a connection (or by jumping to another page via code).

HttpContext.Current.Session and Session are mainly for browser users, all, basically no difference between the two, but not all programs are accessed through the browser.

For example, the user obtains the data through the EXE program, may fail.

In addition HttpContext.Current. is for the current user, and the session is for the web context.

For example, there are 2 pages: The Default.aspx code is as follows

protected void Page_Load (object sender, EventArgs e)
{

System.Threading.Thread threadHand1 = new System.Threading.Thread (() =        {            session["a"] = "a";         });        Threadhand1.start ();                Response.Redirect ("default2.aspx");
}

  

And on another page get

protected void Page_Load (object sender, EventArgs e)    {        Response.Write (session["a"]);    }

This is where you can get it.

And if the above code is modified to

protected void Page_Load (object  sender, EventArgs e)    {            new System.Threading.Thread () =         {           httpcontext.current.session["a" "a" ;         });        Threadhand1.start ();                         Response.Redirect ("default2.aspx");    }

The other page is modified to

protected void Page_Load (object sender, EventArgs e)    {        Response.Write (httpcontext.current.session["a"]);    }

is not available.

Because default1.aspx in the System.Threading.Thread start the context is not default2.aspx in the context.

In short, unless you open the room exe, third-party component interface, etc., otherwise, basically 2 people basically no difference.

The difference between HttpContext.Current.Session and Session

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.