0

Currently i'm working in one migration request, where we need to change the framework from 3.5 to 4.6.2. Here the problem is after changing the framework below method is not showing result as expected. My.User.IsInRole() is returning null.

Could anyone please suggest equivalent code for the above or please suggest steps to resolve the issue in my Visual Studio. Earlier I faced problem with My.User.Name and changed the code to Environment.Username but for this I am unable to find some alternate method.

MatSnow
  • 7,357
  • 3
  • 19
  • 31

1 Answers1

1

My.User.IsInRole() should not return null/Nothing. The return value is a Boolean.

As an alternative you can use System.Security.Principal Namespace like in the following example:

Imports System.Security.Principal

Class PrincipalCheck
    Shared Function UserInRole(role As String) As Boolean
        Dim currPrincipal As New WindowsPrincipal(New WindowsIdentity(Environment.UserName))
        Return currPrincipal.IsInRole(role)
    End Function
End Class

Public Sub StartCheck()
   MsgBox(PrincipalCheck.UserInRole("MyDomain\MyGroup"))
End Sub

But this should return the same result:

MsgBox(My.User.IsInRole("MyDomain\MyGroup"))
MatSnow
  • 7,357
  • 3
  • 19
  • 31