Create a component

  • Thread starter Thread starter ruca
  • Start date Start date
R

ruca

Hi people,

I have a .vb file and I want to create a .dll file.

I'm puting this line in command line:
vbc /t:library
/r:system.dll,system.web.dll,system.data.dll,microsoft.visualbasic.dll
C:\marcacao.vb

The compiler give me errors only because I have both Response and Request
objects in my .vb file.
What do I have to add more in command line?
 
Because you are compiling into a DLL, the DLL doesn't have access to
the response and request objects by default. You have two options.

1.) You could reference system.web.httpcontext.current in your DLL,
which would be the simplest.

2.) Create a class to manage the ASP objects for your DLL, for
example

Imports System
Imports System.Web
Imports System.web.httpcontext
Imports System.Web.SessionState

Public Class ASPObjects
'*********************************************************
'Use this class to reference ASP.Net objects inside a .NET dll
'i.e. Application, Session, Response, Request, etc.
'*********************************************************
Public objHttpContext As HttpContext

Public objHttpResponse As HttpResponse
Public objHttpRequest As HttpRequest
Public objHttpApplication As HttpApplicationState
Public objhttpSession As HttpSessionState
'Public strUserAgent As String

Public Sub New()

' Get the HttpContext object for the current HTTP request.
objHttpContext = HttpContext.Current()

' Get the Application State object.
objHttpApplication = objHttpContext.Application

' Get the Session object.
objhttpSession = objHttpContext.Session

' Get the Response object.
objHttpResponse = objHttpContext.Response

' Get the Request object.
objHttpRequest = objHttpContext.Request

' This code uses the Request object.
' You can use other intrinsic objects in a similar fashion
'strUserAgent =
objHttpRequest.ServerVariables("HTTP_USER_AGENT")

' This code uses the Response object.
'objHttpResponse.Write("HTTP USER AGENT: ")
'objHttpResponse.Write(strUserAgent)
end sub
End Class



Do either of these and you'll be able to access the ASP objects,

Neil
 
Back
Top