. NET Common Sense callcontext

Source: Internet
Author: User

Many people may have questions about httpcontext. Current.

How did he implement it?

Why can different results be obtained when different requests access a static member current?

Obviously, this static object is related to the context of the current call.

Its internal implementation is similar to callcontext. setdata () and callcontext. getdata ()

The data saved through setdata is related to the call stack of the current method. For example, if you set data in the middle of method

Then method A calls Method B, so that method B can use getdata () to obtain data, which is also OK.

The data can be used to each other on this method stack.

For example:Code

    Public     Static  Wcftransaction transaction
{
Get
{
Return Callcontext. logicalgetdata ( " Wcftransaction " ) As Wcftransaction;
}
Set
{
Callcontext. logicalsetdata ( " Wcftransaction " , Value );
}
}

PS: the main difference between logicalgetdata and getdata is that logicalgetdata can adapt to more situations.

For example, when cross-appdomian is used, when setdata is used in another appdomain, getdata cannot get the value, and logicalgetdata can continue to be used,

In addition, if the preceding wcftrancation inherits a specific interface, it can be automatically propagated to more places. However, it is difficult to control the lifecycle.

Callcontext is related to the call stack

In the next article, we will introduce the thread-related data... although these two have a large overlap in most cases ..

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.