My goal is to check if user is member of specific active directory group.
In .net mvc i was using this code inside my service
HttpContext.Current.Request.LogonUserIdentity.Groups
.Any(x => x.Translate(typeof(NTAccount)).Value == "some role"
and it worked well.
In .net core mvc 2.1.2 i pass IHttpContextAccessor
into service constructor and try to use following
_httpAccessor.HttpContext.User.Identity.LogonUserIdentity.Groups
but there is an issue, because Identity
does not contains LogonUserIdentity
. I tried to find any solution but i was not successful, how can i get the list of user groups or check if user is member of specific one ?
_httpAccessor.HttpContext.User.IsInRole("role name")
i think that is what i need.