HttpContext in LDASM

  • Thread starter Thread starter Alexander Inochkin
  • Start date Start date
A

Alexander Inochkin

Hi!

Could you help me to understand next fact...

I open in LDASM System.Web.dll and read:

..method /*060002D7*/ public hidebysig specialname static
class System.Web.HttpContext/* 02000051 */
get_Current() cil managed
// SIG: 00 00 12 81 44
{
// Method begins at RVA 0x20df5
// Code size 16 (0x10)
.maxstack 8
IL_0000: /* 72 | (70)0077F0 */ ldstr "HttpContext" /*
700077F0 */
IL_0005: /* 28 | (0A)00012F */ call object [mscorlib/*
23000001 */]System.Runtime.Remoting.Messaging.CallContext/* 010000E7
*/::GetData(string) /* 0A00012F */
IL_000a: /* 75 | (02)000051 */ isinst
System.Web.HttpContext/* 02000051 */
IL_000f: /* 2A | */ ret
} // end of method HttpContext::get_Current

so I decided that I can get current HttpContext by two ways:

1 -
HttpContext cnt = HttpContext.Current;

2 -
object o =
System.Runtime.Remoting.Messaging.CallContext.GetData("HttpContext");
HttpContext cnt = o as HttpContext;

but in test in second example I get cnt == null....

Question: Why I got different results? What is wrong.


Inochkin Alexander.
 
Alexander Inochkin said:
Hi!

Could you help me to understand next fact...

I open in LDASM System.Web.dll and read:

.method /*060002D7*/ public hidebysig specialname static
class System.Web.HttpContext/* 02000051 */
get_Current() cil managed
// SIG: 00 00 12 81 44
{
// Method begins at RVA 0x20df5
// Code size 16 (0x10)
.maxstack 8
IL_0000: /* 72 | (70)0077F0 */ ldstr "HttpContext" /*
700077F0 */
IL_0005: /* 28 | (0A)00012F */ call object [mscorlib/*
23000001 */]System.Runtime.Remoting.Messaging.CallContext/* 010000E7
*/::GetData(string) /* 0A00012F */
IL_000a: /* 75 | (02)000051 */ isinst
System.Web.HttpContext/* 02000051 */
IL_000f: /* 2A | */ ret
} // end of method HttpContext::get_Current

so I decided that I can get current HttpContext by two ways:

1 -
HttpContext cnt = HttpContext.Current;

2 -
object o =
System.Runtime.Remoting.Messaging.CallContext.GetData("HttpContext");
HttpContext cnt = o as HttpContext;

but in test in second example I get cnt == null....

Question: Why I got different results? What is wrong.


Inochkin Alexander.
 
Hi Alexander,

CallContext is a specialized collection object like a namevaluecollection.
The name is set with SetData Method and we need to use the special name
string when call GetData Method. I haven't read the source code of
system.web.httpcontext, but I think the name may not be "HttpContext" as
sepcified in your code, so that you failed to retireve the object.

Luke
Microsoft Online Support

Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)
 
Back
Top