Assembly Compilation!

A

Adam Knight

Hi all,
I am trying to compile an assembly.

#Code Snippets.

Imports System
Imports System.Web.SessionState.HttpSessionState

Public Function GetGroup() As String

Return Session("GroupId")

End Function

cd mypath
vbc /t:library /r:System.dll /r:System.Web.dll
/out:../../../bin/Security.dll security.vb
pause

I keep getting an error 'Session' is undefined.

Can someone enlighten me as to what i am doing wrong?
 
K

Kevin Spencer

The Session property is a member of classes which implement
System.Web.IHttpHandler System.Web.IHttpModule, and is a part of the
System.Web.HttpContext passed to an IHttpHandler or IHttpModule, such as
System.Web.UI.Page.

Assuming that your class is supposed to work in the context of a Page, you
can obtain a reference to the current Session via the static
System.Web.HttpContext.Current.Handler property. Example:

Dim Session as System.Web.SessionState.HttpSessionState

If Not IsNothing(System.Web.HttpContext.Current.Handler) Then
Session = CType(System.Web.UI.Page)
System.Web.HttpContext.Current.Handler
Return Session("GroupId")
End If
Return ""

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
Neither a follower nor a lender be.
 

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

Members online

No members online now.

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,813
Latest member
lawrwtwinkle111

Latest Threads

Top