Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

Is it not possible to retreive session variables created in a Sub in a Public Shared Function? I get the following error message:

 

"BC30369: Cannot refer to an instance member of a class from within a shared method or shared member initializer without an explicit instance of the class".

 

I underlined the code where the error occurrs.

 

Here's the code:

 

    Sub GetLoggedInUser()
       Dim userID As String
       Dim strFullName As String
       strFullName = User.Identity.Name

       'Get just the corpId (remove the domain info)
       userID = strFullName.Substring(strFullName.IndexOf("\", 0) + 1)
       Session("sUserId") = userID
   End Sub

   Public Shared Function HasPermission() As Boolean
       Dim myCheck As New PermissionCheckClass 'this is the class where the code is located
       myCheck.GetLoggedInUser()

       'Get the users CorpId from the session variable.
       Dim pCorpId As String = CType([u]Session[/u].Item("sUserId"), String)
   End Function

 

Has the problem anything to do with that I have both the sub to set the session variable AND the function to retreive the variable in the same class?

 

Any thoughts appreciated!

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...