HttpContext.Current returns null

G

Gilgamesh

We have a legacy ASP application which is calling a VB 6 DLL. This dll then
calls a C# dll assembly written in .net 2.0. We need to access httpcontext
in C# in order to get the request object associated with the ASP page which
initiated the request. HttpContext.Current retunes null in C#, which
indicates that the object context is not being passed from vb dll to C# dll.
Any idea why is this happening?

Thanks,
Gilgamesh
 
N

Nicholas Paldino [.NET/C# MVP]

Gilgamesh,

Your assumption about the object context not being passed from the VB
dll to the C# dll is incorrect. In ASP.NET, it doesn't know anything about
the HttpContext class, so it's natural that the static Current property
returns null.

Rather, you will have to get the ASP intrinsic objects from COM+.

To do this, you will have to add a COM interop assembly to your project
for "Microsoft Active Server Pages Object". You will also have to set a
reference to System.EnterpriseServices.dll in your project.

Once you do that, when you need to access one of the intrisic object,
you will use the ContextUtils class in the System.EnterpriseServices
namespace. From there, you can call the GetNamedProperty method, passing
"Request", "Response", "Session", "Application", or "Server" to get the
appropriate intrinsic object. Cast the return value to the appropriate
interface type in the type library you created the interop assembly for, and
you should be able to use the ASP intrinsic object from there.

For more information on how to do this in VB6, see the following
article:

http://www.stardeveloper.com/articles/display.html?article=2000041401&page=1

This points out how you do it in VB6. The ContextUtil class in .NET
will handle the interaction with the ObjectContext, you just have to cast it
to the right return value.
 
G

Guest

Pefecto! Boy does that take me back to ancient history...

-- Peter
http://www.eggheadcafe.com
unBlog: http://petesbloggerama.blogspot.com
BlogMetaFinder: http://www.blogmetafinder.com



Nicholas Paldino said:
Gilgamesh,

Your assumption about the object context not being passed from the VB
dll to the C# dll is incorrect. In ASP.NET, it doesn't know anything about
the HttpContext class, so it's natural that the static Current property
returns null.

Rather, you will have to get the ASP intrinsic objects from COM+.

To do this, you will have to add a COM interop assembly to your project
for "Microsoft Active Server Pages Object". You will also have to set a
reference to System.EnterpriseServices.dll in your project.

Once you do that, when you need to access one of the intrisic object,
you will use the ContextUtils class in the System.EnterpriseServices
namespace. From there, you can call the GetNamedProperty method, passing
"Request", "Response", "Session", "Application", or "Server" to get the
appropriate intrinsic object. Cast the return value to the appropriate
interface type in the type library you created the interop assembly for, and
you should be able to use the ASP intrinsic object from there.

For more information on how to do this in VB6, see the following
article:

http://www.stardeveloper.com/articles/display.html?article=2000041401&page=1

This points out how you do it in VB6. The ContextUtil class in .NET
will handle the interaction with the ObjectContext, you just have to cast it
to the right return value.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Gilgamesh said:
We have a legacy ASP application which is calling a VB 6 DLL. This dll
then calls a C# dll assembly written in .net 2.0. We need to access
httpcontext in C# in order to get the request object associated with the
ASP page which initiated the request. HttpContext.Current retunes null in
C#, which indicates that the object context is not being passed from vb
dll to C# dll. Any idea why is this happening?

Thanks,
Gilgamesh
 
L

Liz

We have a legacy ASP application which is calling a VB 6 DLL. This dll
then calls a C# dll assembly written in .net 2.0. We need to access
httpcontext in C# in order to get the request object associated with the
ASP page which initiated the request. HttpContext.Current retunes null in
C#, which indicates that the object context is not being passed from vb
dll to C# dll. Any idea why is this happening?


you can't just access Request directly in the legacy ASP app? isn't this
what you call the really long way around? which gets even worse when
Nicholas explains what it takes to do it?

hope that VB6 and C# code is doing something really useful ....
 
N

Nicholas Paldino [.NET/C# MVP]

Liz,

No, you can't. The Request, Response, etc, etc, objects in ASP are
completely different than they are in ASP.NET. ASP.NET doesn't improve or
enhance ASP (technically), it completely replaced it.

Because of that, you have to get the intrinsic objects the way you would
do in ASP, which is what I pointed out, using some of the wrappers that .NET
provides for accessing COM+.

A COM component accessed in ASP would have to do the same thing to get
the Request, Response, etc, etc properties.
 
L

Liz

Liz,

No, you can't. The Request, Response, etc, etc, objects in ASP are
completely different than they are in ASP.NET. ASP.NET doesn't improve or
enhance ASP (technically), it completely replaced it.

Because of that, you have to get the intrinsic objects the way you
would do in ASP, which is what I pointed out, using some of the wrappers
that .NET provides for accessing COM+.

A COM component accessed in ASP would have to do the same thing to get
the Request, Response, etc, etc properties.

Nicholas -

the OP said they are running a legacy ASP application ... so he's got direct
access to Request; what he's doing with his VB6 COM component + his C#
assembly is not specified ... it all sounds very contorted and I am
wondering if it needs to be ... in all events, so far as I can see from what
was posted, the question isn't really about ASP.NET at all as they don't
appear to be using it. If he needs to pass anything from Request to his VB
component, I should think he can, no?

Are you assuming this all refers to an app being converted to ASP.NET?
maybe it is, but the post doesn't say that ... why there is a C# assembly in
the picture I have no idea ... but people decide to do all kinds of things
for all kinds of reasons, some of them better than others


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Liz said:
you can't just access Request directly in the legacy ASP app? isn't this
what you call the really long way around? which gets even worse when
Nicholas explains what it takes to do it?

hope that VB6 and C# code is doing something really useful ....
 
N

Nicholas Paldino [.NET/C# MVP]

Liz,

The .NET class is being accessed by the VB6 class, as the OP stated.

Yes, the OP could pass the intrinsic Request, Response, etc, etc objects
from the VB6 object to the .NET class, but from the original post, it
doesn't seem the OP wants to do that. This is because the OP is looking to
get the intrinsic objects from the static Current property on the
HttpContext class. This is how you get the intrinsic objects in ASP.NET.
In classic ASP (which is what this is running in) the solution I provided is
how you would get the intrinsic objects.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Liz said:
Liz,

No, you can't. The Request, Response, etc, etc, objects in ASP are
completely different than they are in ASP.NET. ASP.NET doesn't improve
or enhance ASP (technically), it completely replaced it.

Because of that, you have to get the intrinsic objects the way you
would do in ASP, which is what I pointed out, using some of the wrappers
that .NET provides for accessing COM+.

A COM component accessed in ASP would have to do the same thing to get
the Request, Response, etc, etc properties.

Nicholas -

the OP said they are running a legacy ASP application ... so he's got
direct access to Request; what he's doing with his VB6 COM component +
his C# assembly is not specified ... it all sounds very contorted and I am
wondering if it needs to be ... in all events, so far as I can see from
what was posted, the question isn't really about ASP.NET at all as they
don't appear to be using it. If he needs to pass anything from Request to
his VB component, I should think he can, no?

Are you assuming this all refers to an app being converted to ASP.NET?
maybe it is, but the post doesn't say that ... why there is a C# assembly
in the picture I have no idea ... but people decide to do all kinds of
things for all kinds of reasons, some of them better than others


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Liz said:
We have a legacy ASP application which is calling a VB 6 DLL. This dll
then calls a C# dll assembly written in .net 2.0. We need to access
httpcontext in C# in order to get the request object associated with
the ASP page which initiated the request. HttpContext.Current retunes
null in C#, which indicates that the object context is not being passed
from vb dll to C# dll. Any idea why is this happening?


you can't just access Request directly in the legacy ASP app? isn't
this what you call the really long way around? which gets even worse
when Nicholas explains what it takes to do it?

hope that VB6 and C# code is doing something really useful ....
 
L

Liz

Nicholas --

I don't know what the OP is actually trying to do based on the post .. but
it sounded like a chain of:

ASP(classic) --> VB6.DLL --> C# Method

and what he specifically wanted available to the C# code were elements of
the Request collection ... he may have said that he wanted
HttpContext.Current but coming from ASP classic there is none (which you
probably already said) but there is the functional equivalent; but I guess
there's little point in you and I debating what a third party is trying to
do ...


Nicholas Paldino said:
Liz,

The .NET class is being accessed by the VB6 class, as the OP stated.

Yes, the OP could pass the intrinsic Request, Response, etc, etc
objects from the VB6 object to the .NET class, but from the original post,
it doesn't seem the OP wants to do that. This is because the OP is
looking to get the intrinsic objects from the static Current property on
the HttpContext class. This is how you get the intrinsic objects in
ASP.NET. In classic ASP (which is what this is running in) the solution I
provided is how you would get the intrinsic objects.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Liz said:
Liz,

No, you can't. The Request, Response, etc, etc, objects in ASP are
completely different than they are in ASP.NET. ASP.NET doesn't improve
or enhance ASP (technically), it completely replaced it.

Because of that, you have to get the intrinsic objects the way you
would do in ASP, which is what I pointed out, using some of the wrappers
that .NET provides for accessing COM+.

A COM component accessed in ASP would have to do the same thing to
get the Request, Response, etc, etc properties.

Nicholas -

the OP said they are running a legacy ASP application ... so he's got
direct access to Request; what he's doing with his VB6 COM component +
his C# assembly is not specified ... it all sounds very contorted and I
am wondering if it needs to be ... in all events, so far as I can see
from what was posted, the question isn't really about ASP.NET at all as
they don't appear to be using it. If he needs to pass anything from
Request to his VB component, I should think he can, no?

Are you assuming this all refers to an app being converted to ASP.NET?
maybe it is, but the post doesn't say that ... why there is a C# assembly
in the picture I have no idea ... but people decide to do all kinds of
things for all kinds of reasons, some of them better than others


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)



We have a legacy ASP application which is calling a VB 6 DLL. This dll
then calls a C# dll assembly written in .net 2.0. We need to access
httpcontext in C# in order to get the request object associated with
the ASP page which initiated the request. HttpContext.Current retunes
null in C#, which indicates that the object context is not being
passed from vb dll to C# dll. Any idea why is this happening?


you can't just access Request directly in the legacy ASP app? isn't
this what you call the really long way around? which gets even worse
when Nicholas explains what it takes to do it?

hope that VB6 and C# code is doing something really useful ....
 
G

Gilgamesh

Nicholas,
How do I add a COM interop assembly to my project for "Microsoft Active
Server Pages Object", as you've stated? Just to clarify the program again. I
need to access IIS intrinstic objects from within a C# assembly which has
been instantiated by a VB 6 DLL.

Thanks,
-G


Nicholas Paldino said:
Gilgamesh,

Your assumption about the object context not being passed from the VB
dll to the C# dll is incorrect. In ASP.NET, it doesn't know anything
about the HttpContext class, so it's natural that the static Current
property returns null.

Rather, you will have to get the ASP intrinsic objects from COM+.

To do this, you will have to add a COM interop assembly to your project
for "Microsoft Active Server Pages Object". You will also have to set a
reference to System.EnterpriseServices.dll in your project.

Once you do that, when you need to access one of the intrisic object,
you will use the ContextUtils class in the System.EnterpriseServices
namespace. From there, you can call the GetNamedProperty method, passing
"Request", "Response", "Session", "Application", or "Server" to get the
appropriate intrinsic object. Cast the return value to the appropriate
interface type in the type library you created the interop assembly for,
and you should be able to use the ASP intrinsic object from there.

For more information on how to do this in VB6, see the following
article:

http://www.stardeveloper.com/articles/display.html?article=2000041401&page=1

This points out how you do it in VB6. The ContextUtil class in .NET
will handle the interaction with the ObjectContext, you just have to cast
it to the right return value.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Gilgamesh said:
We have a legacy ASP application which is calling a VB 6 DLL. This dll
then calls a C# dll assembly written in .net 2.0. We need to access
httpcontext in C# in order to get the request object associated with the
ASP page which initiated the request. HttpContext.Current retunes null in
C#, which indicates that the object context is not being passed from vb
dll to C# dll. Any idea why is this happening?

Thanks,
Gilgamesh
 
A

Anthony Jones

Gilgamesh said:
Nicholas,
How do I add a COM interop assembly to my project for "Microsoft Active
Server Pages Object", as you've stated? Just to clarify the program again. I
need to access IIS intrinstic objects from within a C# assembly which has
been instantiated by a VB 6 DLL.


Use the Browse tab in the Add Reference dialog and find
System32/inetsrv/asp.dll
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top