Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations John Tel on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

get ServerVariables from .asp site 1

Status
Not open for further replies.

bmpsu

Programmer
Jan 13, 2005
128
US
I have a .Net(2.0) dll that tracks logon information. I have the dll registered on my server. When I call this dll from another .net site, I have no problems. I need to call this dll from a .asp site on this server as well. I want the dll to be able to get a few server variables from whichever site makes the call. Before I would just pass those variables into the function inside my dll, but would rather just get them inside the .net code. I think it is the way I am requesting my serverVariables...but not sure. Or am I completely off base.

Some example code:
(counter.vb)
Code:
'.NET code
Public Sub track()
Dim sUrl,sLclAddr as String
sUrl = System.Web.HttpContext.Current.Request.ServerVariables("URL")
sLclAddr = System.Web.HttpContext.Current.Request.ServerVariables("LOCAL_ADDR")
'...then do some stuff with this information...
End Sub

Site1\logon.asp
Code:
'.asp code
<%@ Language=VBScript %>
<%
Sub trackSome()
Dim Cntr
Set Cntr = Server.CreateObject("counter")
Call Cntr.track()
End Sub

If logon = "unSuccessful" Then
Call trackSome
End If
%>
'...do some more stuff...
 
I figured I would post what I found. Mostly from googling. I think I should have phrased my question differently as well. I found that this search phrase can get you good leads - "accessing intrinsic ASP objects from .Net Class", or something close.

If I state anything incorrectly, please correct me. I am not all that great with terminology.

I have already created a .Net 2.0 Class Library signed with a strong name key file. My intentions are to register the dll on my web server into the gac utility. I found that the .Net class cannot access the Request object when called from an ASP 3.0 web page. However, this .Net class can access the System.Web.HttpContext.Current.Request object from other .Net applications.

I opened my VS2005 project. I added two more references.
1. System.EnterpriseServices
2. Microsoft Active Server Pages Object Library (Interop.ASPTypeLibrary.dll) *Type = COM
Then some sample code like this:
Code:
Imports System.EnterpriseServices
Imports ASPTypeLibrary
Imports System.Web
Imports ...

<ComVisible(True)> _
Public Class myClass
Public Sub track()
 Dim lclAddr As String
 Dim objHttpContext As HttpContext
 objHttpContext = HttpContext.Current
 If Not objHttpContext Is Nothing Then
  lclAddr = objHttpContext.Request.ServerVariables("LOCAL_ADDR")
 Else
  Dim objRequest As ASPTypeLibrary.Request
  objRequest = CType(ContextUtil.GetNamedProperty("Request"), ASPTypeLibrary.Request)
  lclAddr = CType(objRequest.ServerVariables("LOCAL_ADDR"), IStringList)(1)
 End If

...
End Sub
End Class

This all seems to work. Though the above is just a simple example, but I think I have captured the idea. I have some concerns about over-head. Wonder if there is a better way.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top