Accessing intrinsic ASP (not ASP.NET) objects from .NET class

  • Thread starter Thread starter Alek Davis
  • Start date Start date
A

Alek Davis

Hi,

Is it possible to access intrinsic ASP objects, such as Request, from a .NET
class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can
this library retrieve the request info (basically, server variables exposed
via the Request object), when it is invoked from a traditional ASP (not
ASP.NET) application? Any ideas? Thanks in advance.

Alek
 
Alek said:
Hi,

Is it possible to access intrinsic ASP objects, such as Request, from a .NET
class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can
this library retrieve the request info (basically, server variables exposed
via the Request object), when it is invoked from a traditional ASP (not
ASP.NET) application? Any ideas? Thanks in advance.

Alek

You can try System.Web.HttpContext.Current.Request (.Current may not be
needed), etc., but I don't know if that context is transferred and can
be read correctly in the ASP.NET. Never done this before myself, tho,
just something to try...
 
No, this does not work. Current.Request attempts to retrieve the intrinsic
object of ASP.NET application, so when it is called from an ASP application,
its values is set to NULL. As I understand ASP and ASP.NET use different
intrinsic objects. There must be a way of doing this. Thanks for the
suggestion, though.

Alek
 
no. because your .net class is called from asp, not aspx, there is no .net
request object or stream.

backgroup, in aspx, asp runs in a seperate process, and uses a named pipes
to communicate to the iis process. the .net response object writes to this
pipe. obviously if you .net object is hosted by asp, this pipe does not
exist.

you will need to add a method to you class where the asp can register the
com based Request object, so the .net code can talk to it.

-- bruce (sqlwork.com)
 
Yeah, I understand that the ASP.NET Request object is useless in this case,
but I am wondering how to retrieve the Request from ASP. It is definitely
available (at least internally, at some level), so there must be a way to
get to it (hopefully). Maybe through interop or some hacking technique? Good
info about pipes (thanks), I did not know that.
 
the asp request object is a standard com object. you can create a .net
wrapper for it, or use the com interop library.

-- bruce (sqlwork.com)
 
Regardless of whather you can use the ASP Request COM object from a wrapper,
you still can't get into the ASP application space.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
Are you sure? Please excuse my ignorance, but logically, since the call is
made from an ASP application, shouldn't ASP info be presents on some level?
I mean, if I have a standard Win32 COM object, I can get IRequest info from
the application context (IObjectContext) obtained via GetObjectContext API.
Can't I do something similar from a .NET assembly, maybe via interop?
 
You might possibly be able to poke around in memory using pointers and API
calls. Seems like going the long (and dangerous) way round, though. I would
think using Message Queuing would be much simpler and safer.

--
HTH,
Kevin Spencer
..Net Developer
Microsoft MVP
Big things are made up
of lots of little things.
 
OK, I think I figured it out. In case you need to do something similar try
to follow these steps:

(1) Add a reference to System.EnterpriseServices namespace (you need to add
a DLL along with using/Imports statement).
(2) Open project properties and add a reference to your SNK (key) file in
the Wrapper Assembly Key File under Wrapper Assembly ActiveX/COM Objects
heading (in General properties).
(3) Add a COM reference (using the middle tab of the Add Reference dialog)
to ASP.DLL. This DLL implements intrinsic ASP COM objects, such as Request,
Response, etc. It is supposed to be located under the
%WINDIR%\System32\inetsrv folder. When you complete this step VS.NET will
generate a proxy DLL called ASPTypeLibrary, sign it with the key from the
file you specified in step 2 and copy it to your project. You will use this
DLL to reference the intrinsic ASP COM objects. You will need to deploy this
DLL along with your app.
(4) Add a reference to the ASPTypeLibrary namespace (via using/Imports
statement).
(5) To access an intrinsic ASP COM object, call the
ContextUtil.GetNamedProperty method passing the name of the object you are
interested in, such as

// Request is defined in ASPTypeLibrary.
Request request = (Request)ContextUtil.GetNamedProperty("Request");

(6) Now you can use the Request object. It may be a bit tricky, though. For
example, this is how you retrieve the value of the REMOTE_HOST server
variable:

// Apparently, the array elements start with index 1, not 0.
string host =
((IStringList)request.ServerVariables["REMOTE_HOST"])[1].ToString();

For more info, check
http://www.gotdotnet.com/team/xmlentsvcs/esfaq.aspx#13.1 (it has a VB
version as well).

Alek
 
One correction: The actual name of the ASPTypeLibrary file is
Interop.ASPTypeLibrary.dll.

Alek

Alek Davis said:
OK, I think I figured it out. In case you need to do something similar try
to follow these steps:

(1) Add a reference to System.EnterpriseServices namespace (you need to add
a DLL along with using/Imports statement).
(2) Open project properties and add a reference to your SNK (key) file in
the Wrapper Assembly Key File under Wrapper Assembly ActiveX/COM Objects
heading (in General properties).
(3) Add a COM reference (using the middle tab of the Add Reference dialog)
to ASP.DLL. This DLL implements intrinsic ASP COM objects, such as Request,
Response, etc. It is supposed to be located under the
%WINDIR%\System32\inetsrv folder. When you complete this step VS.NET will
generate a proxy DLL called ASPTypeLibrary, sign it with the key from the
file you specified in step 2 and copy it to your project. You will use this
DLL to reference the intrinsic ASP COM objects. You will need to deploy this
DLL along with your app.
(4) Add a reference to the ASPTypeLibrary namespace (via using/Imports
statement).
(5) To access an intrinsic ASP COM object, call the
ContextUtil.GetNamedProperty method passing the name of the object you are
interested in, such as

// Request is defined in ASPTypeLibrary.
Request request = (Request)ContextUtil.GetNamedProperty("Request");

(6) Now you can use the Request object. It may be a bit tricky, though. For
example, this is how you retrieve the value of the REMOTE_HOST server
variable:

// Apparently, the array elements start with index 1, not 0.
string host =
((IStringList)request.ServerVariables["REMOTE_HOST"])[1].ToString();

For more info, check
http://www.gotdotnet.com/team/xmlentsvcs/esfaq.aspx#13.1 (it has a VB
version as well).

Alek

Alek Davis said:
Hi,

Is it possible to access intrinsic ASP objects, such as Request, from a .NET
class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can
this library retrieve the request info (basically, server variables exposed
via the Request object), when it is invoked from a traditional ASP (not
ASP.NET) application? Any ideas? Thanks in advance.

Alek
 
Just wanted to post for people that Step #2 of this solution below
works only in C#. The project properties in regards to Wrapper
Assembly do not exist in VB.NET applications. See the following MS
Article for more.

http://support.microsoft.com/?kbid=313666




Alek Davis said:
One correction: The actual name of the ASPTypeLibrary file is
Interop.ASPTypeLibrary.dll.

Alek

Alek Davis said:
OK, I think I figured it out. In case you need to do something similar try
to follow these steps:

(1) Add a reference to System.EnterpriseServices namespace (you need to add
a DLL along with using/Imports statement).
(2) Open project properties and add a reference to your SNK (key) file in
the Wrapper Assembly Key File under Wrapper Assembly ActiveX/COM Objects
heading (in General properties).
(3) Add a COM reference (using the middle tab of the Add Reference dialog)
to ASP.DLL. This DLL implements intrinsic ASP COM objects, such as Request,
Response, etc. It is supposed to be located under the
%WINDIR%\System32\inetsrv folder. When you complete this step VS.NET will
generate a proxy DLL called ASPTypeLibrary, sign it with the key from the
file you specified in step 2 and copy it to your project. You will use this
DLL to reference the intrinsic ASP COM objects. You will need to deploy this
DLL along with your app.
(4) Add a reference to the ASPTypeLibrary namespace (via using/Imports
statement).
(5) To access an intrinsic ASP COM object, call the
ContextUtil.GetNamedProperty method passing the name of the object you are
interested in, such as

// Request is defined in ASPTypeLibrary.
Request request = (Request)ContextUtil.GetNamedProperty("Request");

(6) Now you can use the Request object. It may be a bit tricky, though. For
example, this is how you retrieve the value of the REMOTE_HOST server
variable:

// Apparently, the array elements start with index 1, not 0.
string host =
((IStringList)request.ServerVariables["REMOTE_HOST"])[1].ToString();

For more info, check
http://www.gotdotnet.com/team/xmlentsvcs/esfaq.aspx#13.1 (it has a VB
version as well).

Alek

Alek Davis said:
Hi,

Is it possible to access intrinsic ASP objects, such as Request, from a .NET
class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can
this library retrieve the request info (basically, server variables exposed
via the Request object), when it is invoked from a traditional ASP (not
ASP.NET) application? Any ideas? Thanks in advance.

Alek
 
Hi Alex,

I have tried to follow your steps but was wondering if you had any example
code you could send me or point me in the right direction.

Bascially I have some old ASP 3.0 (Classic pages) that perform a upload of a
file via a form post. I would like to write a C# component that can use the
ASP 3.0 intrinsic objects especially the Request.BinaryRead to save the file
on a remote sever.

I have followed the technet article

http://support.microsoft.com/default.aspx?scid=kb;en-us;810928&Product=aspnet

using the ASP.NET intrinsic objects and this works fine the file uploads.

I then created a COM callable wrapper using:

tlbexp myComp.dll /out:myComp.tlb

regasm /tlb=myComp.tlb MyComp.dll

gacutil /i myComp.dll

and created ASP 3.0 classic pages to perform the form post but I get the
following error:

'Object reference not set to an instance of an object'


Alek Davis said:
OK, I think I figured it out. In case you need to do something similar try
to follow these steps:

(1) Add a reference to System.EnterpriseServices namespace (you need to add
a DLL along with using/Imports statement).
(2) Open project properties and add a reference to your SNK (key) file in
the Wrapper Assembly Key File under Wrapper Assembly ActiveX/COM Objects
heading (in General properties).
(3) Add a COM reference (using the middle tab of the Add Reference dialog)
to ASP.DLL. This DLL implements intrinsic ASP COM objects, such as Request,
Response, etc. It is supposed to be located under the
%WINDIR%\System32\inetsrv folder. When you complete this step VS.NET will
generate a proxy DLL called ASPTypeLibrary, sign it with the key from the
file you specified in step 2 and copy it to your project. You will use this
DLL to reference the intrinsic ASP COM objects. You will need to deploy this
DLL along with your app.
(4) Add a reference to the ASPTypeLibrary namespace (via using/Imports
statement).
(5) To access an intrinsic ASP COM object, call the
ContextUtil.GetNamedProperty method passing the name of the object you are
interested in, such as

// Request is defined in ASPTypeLibrary.
Request request = (Request)ContextUtil.GetNamedProperty("Request");

(6) Now you can use the Request object. It may be a bit tricky, though. For
example, this is how you retrieve the value of the REMOTE_HOST server
variable:

// Apparently, the array elements start with index 1, not 0.
string host =
((IStringList)request.ServerVariables["REMOTE_HOST"])[1].ToString();

For more info, check
http://www.gotdotnet.com/team/xmlentsvcs/esfaq.aspx#13.1 (it has a VB
version as well).

Alek

Alek Davis said:
Hi,

Is it possible to access intrinsic ASP objects, such as Request, from a ..NET
class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can
this library retrieve the request info (basically, server variables exposed
via the Request object), when it is invoked from a traditional ASP (not
ASP.NET) application? Any ideas? Thanks in advance.

Alek
 
Hi again,

I have managed to get access to the Request object and now would like to
perform a Request.BinaryRead and write the contents of the file to disk.
Does anyone know how I can do this?

Thanks
Msuk

msuk said:
Hi Alex,

I have tried to follow your steps but was wondering if you had any example
code you could send me or point me in the right direction.

Bascially I have some old ASP 3.0 (Classic pages) that perform a upload of a
file via a form post. I would like to write a C# component that can use the
ASP 3.0 intrinsic objects especially the Request.BinaryRead to save the file
on a remote sever.

I have followed the technet article

http://support.microsoft.com/default.aspx?scid=kb;en-us;810928&Product=aspnet

using the ASP.NET intrinsic objects and this works fine the file uploads.

I then created a COM callable wrapper using:

tlbexp myComp.dll /out:myComp.tlb

regasm /tlb=myComp.tlb MyComp.dll

gacutil /i myComp.dll

and created ASP 3.0 classic pages to perform the form post but I get the
following error:

'Object reference not set to an instance of an object'


Alek Davis said:
OK, I think I figured it out. In case you need to do something similar try
to follow these steps:

(1) Add a reference to System.EnterpriseServices namespace (you need to add
a DLL along with using/Imports statement).
(2) Open project properties and add a reference to your SNK (key) file in
the Wrapper Assembly Key File under Wrapper Assembly ActiveX/COM Objects
heading (in General properties).
(3) Add a COM reference (using the middle tab of the Add Reference dialog)
to ASP.DLL. This DLL implements intrinsic ASP COM objects, such as Request,
Response, etc. It is supposed to be located under the
%WINDIR%\System32\inetsrv folder. When you complete this step VS.NET will
generate a proxy DLL called ASPTypeLibrary, sign it with the key from the
file you specified in step 2 and copy it to your project. You will use this
DLL to reference the intrinsic ASP COM objects. You will need to deploy this
DLL along with your app.
(4) Add a reference to the ASPTypeLibrary namespace (via using/Imports
statement).
(5) To access an intrinsic ASP COM object, call the
ContextUtil.GetNamedProperty method passing the name of the object you are
interested in, such as

// Request is defined in ASPTypeLibrary.
Request request = (Request)ContextUtil.GetNamedProperty("Request");

(6) Now you can use the Request object. It may be a bit tricky, though. For
example, this is how you retrieve the value of the REMOTE_HOST server
variable:

// Apparently, the array elements start with index 1, not 0.
string host =
((IStringList)request.ServerVariables["REMOTE_HOST"])[1].ToString();

For more info, check
http://www.gotdotnet.com/team/xmlentsvcs/esfaq.aspx#13.1 (it has a VB
version as well).

Alek

Alek Davis said:
Hi,

Is it possible to access intrinsic ASP objects, such as Request, from a ..NET
class. Say, I have a .NET library exposed via a COM or COM+ wrapper. Can
this library retrieve the request info (basically, server variables exposed
via the Request object), when it is invoked from a traditional ASP (not
ASP.NET) application? Any ideas? Thanks in advance.

Alek
 
How are you able to access classic asp objects in .NET?

..NET does expose objects of the same name as the ones in classic asp
(Server, Application, Session, Request, Response) but these are not the
*same* instances as the classic asp objects. The .NET versions are held in
a separate memory space and although the object names seem the same, the
data they hold is not.

For example, if you were to set a Session variable on a classic asp page and
then navigate to an asp.net page in the same site and try to access that
session variable, you would not be able to retrieve it. This is because the
session object that exists in classic asp is not the same session object
that is available in asp .net..

-Scott

adieu said:
i am able to access the asp objects in .net but not able to parse it.
Is there any sampe code on how to parse the ASP request object in C#. i
am
looking to get the form variables and the uploaded file . from the
request
[quoted text clipped - 5 lines]
Posted via DevelopmentNow.com Groups
http://www.developmentnow.com/g/

No. .NET does not have access to classic asp objects.

-Scott
 
Back
Top