HttpContext.Current always returns NULL when called from Classic ASP

  • Thread starter Thread starter MATTK
  • Start date Start date
M

MATTK

Hello,

I am porting my existing ASP business logic into C#, compiling as an
application, then using COM callable wrappers to instantiate the
application under ASP.

I am trying to use HttpContext.Current.Request.MapPath in my c# code,
but when I call the code from ASP HttpContext.Current returns NULL
every time.

Please note that this is NOT ASP.NET, but that I am using this on an
existing ASP page.

My problem is that HttpContext.Current always returns NULL, which
means that I cannot use the members of this class to grab these
important objects.

Does anyone know how to do this?
 
MATTK said:
Hello,

I am porting my existing ASP business logic into C#, compiling as an
application, then using COM callable wrappers to instantiate the
application under ASP.

I am trying to use HttpContext.Current.Request.MapPath in my c# code,
but when I call the code from ASP HttpContext.Current returns NULL
every time.

Please note that this is NOT ASP.NET, but that I am using this on an
existing ASP page.

My problem is that HttpContext.Current always returns NULL, which
means that I cannot use the members of this class to grab these
important objects.

Does anyone know how to do this?

You won't have an HttpContext in classic ASP. You need the COM+ Context,
which has references to the ASP Request, Response, Server, Application and
Session objects.

Add references to the System.EnterpriseServices.dll and the AspTypeLibrary
COM component. Then you can get the objects like this:

ASPTypeLibrary.Request Request = (ASPTypeLibrary.Request)
System.EnterpriseServices.ContextUtil.GetNamedProperty("Request");

David
 
I am trying to use the ciode suggested. I have the following code (that works as a class in asp.net) but compiled into a dll and used in a classic asp page I get an error "System.__ComObject"

Here is the code:

if(System.Web.HttpContext.Current != null)
{
strRemoteAddr = System.Web.HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"].ToString();
}
else
{
try
{

ASPTypeLibrary.Request oRequest = (ASPTypeLibrary.Request)
System.EnterpriseServices.ContextUtil.GetNamedProperty("Request");
strRemoteAddr = oRequest.ServerVariables["REMOTE_ADDR"].ToString();
}
catch(Exception e)
{
m_lastfailurereason = "Sorry, method for obtaining remote address failed" + m_remoteAddr + "Exception: " + e.ToString();
return false;
}
}

Can you suggest how it could be made to work?


From http://www.developmentnow.com/g/6_2...-returns-NULL-when-called-from-Classic-ASP.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
I am using code like the above

oRequest = (ASPTypeLibrary.Request)ContextUtil.GetNamedProperty("Request");

trying to get the client's I.P. address

strRemoteAddr = oRequest.ServerVariables["REMOTE_ADDR"].ToString();

but the asp page gives only

System.__ComObject

Is there some other way to get the client's ip address in a C# class -> dll -> asp page?




From http://www.developmentnow.com/g/6_2...-returns-NULL-when-called-from-Classic-ASP.ht

Posted via DevelopmentNow.com Group
http://www.developmentnow.com
 
Try posting your question to microsoft.public.dotnet.framework.aspnet, or
if it's classic ASP, find a classic ASP group.

Robin S.
 
Back
Top