My.user.IsInRole always returning false

旧巷老猫 提交于 2019-12-02 17:05:33

问题


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 always returning false.

If My.User.IsInRole(nlRole.InnerText) Then
   hasRole = True
   Exit For
End If

Also, I tested with below code:

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 no luck. Can someone please help me with the above issue.

If you expect some more input from my end, please let me know.

来源:https://stackoverflow.com/questions/49297752/my-user-isinrole-always-returning-false

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!