-1

I have a query regarding the public shared method, I have an error that indicates BC30369: Cannot refer to an instance member of a class from a shared method.

I have the error in:

strUsuarioapp = ucase (user.identity.Name.split ("\") (0))

exactly in user at the line ucase(user.identity.Name.split ("\") (0))

returns the data I need (domain user), I tried with another ucase(system.environment.usernane), but depending on the environment it gives me different values, while user.identity.Name does not fail me.

I understand the error reference but I don't know how to pass the value, it is mandatory that the method be shared.

I can't remove the shared from the method, is there any code to pass the value of user.identity.Name to it without giving me an error? code:

public class frmview1
    inherits system.web.ui.page
    public pstruserApp as string

public property strUsuarioapp () as string
    get
      return pstruserapp
    end get
      set (value as string)
      pstrUsuarioapp = value
    end set
end property

public shared function usercall (byval name as string, byval namev as string) as string
   dim strUsuarioapp = ucase (user.identity.Name.split ("\") (0))
   ' Error here
   ' ....
   ' ....
    return strresult
end function
Giancarlo
  • 169
  • 11
  • Try using `System.Web.HttpContext.Current.User` instead of `Page.User`. – 41686d6564 stands w. Palestine Aug 26 '21 at 23:00
  • there is a lot of code associated with page.user,I would like to keep it like this if possible. Thank you. – Giancarlo Aug 26 '21 at 23:19
  • They both return the same object. `Page.User` is just a shortcut for `HttpContext.Current.User`. Since you want to access the User object from a Shared method, you should use the global one. You may still use Page.User for instance methods. – 41686d6564 stands w. Palestine Aug 26 '21 at 23:28
  • Does this answer your question? [How to get current user who's accessing an ASP.NET application?](https://stackoverflow.com/questions/5417125/how-to-get-current-user-whos-accessing-an-asp-net-application) – 41686d6564 stands w. Palestine Aug 26 '21 at 23:29
  • I think it would be: Environment.Usename for the DOMAIN username, but I am not sure if it is the user who accesses the page or the domain user of the machine where the web was published. – Giancarlo Aug 26 '21 at 23:41

1 Answers1

0

add user parameter to your function

pubic shared function usercall (byref System.Security.Principal.Principal user,  byval name as string, byval namev as string) as string
   dim strUsuarioapp = ucase (user.identity.Name.split ("\") (0))
   'here Err
....
......

return strresult
end function
Serge
  • 40,935
  • 4
  • 18
  • 45