Hey
I've made a custom principal and identity object. On login it uses the Windows identity to get the current users name and then gets the users id from my db. So basically Windows is handling the username/password. It all works well except IsInRole.
public
override bool IsInRole(string role){
IPrincipal principal = new WindowsPrincipal(WindowsIdentity.GetCurrent()); return principal.IsInRole(role);}
When I pass in a role that I know (from a testing POV) the I'm in the method works! It return true. If I pass in a role name that the user is not in it throws a system exception with the msg "The trust relationship between the primary domain and the trusted domain failed.".
bool inRole = ApplicationContext.User.IsInRole("COMPANYNAME_TTadmin")); // OK bool inRole = ApplicationContext.User.IsInRole("test")) // inRole should = false but it throws an exception instead
Any one know why?
Thanks
George
As I said previously albeit not very clearly, the excpetion thrown is of type SystemException. I can't step into the method as it's in the WindowsPrincipal class (.NET code), can I?
Message: The trust relationship between the primary domain and the trusted domain failed.
Exception thrown in: System.Security.Principal.NTAccount.TranslateToSids(IdentityReferenceCollection sourceAccounts, Boolean& someFailed)
The strangest this is how the exception is not thrown if the user is in the role. My work around is too just catch the exception and return false from my method. It work but it pretty nasty code.
Is there any piece of info the would be particularly help?
Cheers.
In the past to get User.IsInRole to work properly I've had to add in the domain to the group name:
if (User.IsInRole("domain\\group")) {
blah blah blah
}
Hey Stacy, thanks a lot, including the domain name solved the problem. I guess that stops Windows looking for the group name in other domains that the user doesn't actually have permission to access.
Thanks for your input Andy.
Tar very much. George.
Copyright (c) Marimer LLC