Expect the Unexpected: bool IsInRole(string role)

Posted by Ryan Baxter Tue, 10 Jul 2007 02:34:00 GMT

Running some tests yesterday, I was alarmed by an Exception that read, “The trust relationship between the primary domain and the trusted domain failed.” What?!? This code worked a few weeks ago! The method in question called Page.User.IsInRole(“DomainName\RoleName”) to determine if a user was assigned to an administrator’s role. bool IsAdministrator(). Simple and efficient. Why is this happening?!?

IsInRole

In short, the role that I was supplying Page.User.IsInRole with contained a typo. What is interesting is the results of my test case found below. Pay attention to the method signatures and their outcome.

Page.User.IsInRole(“DomainName\RoleName”) returns true
Page.User.IsInRole(“RoleName”) returns true

Page.User.IsInRole(“DomainName\TypoRoleName”) returns false

But…

Page.User.IsInRole(“TypoRoleName”) throws the Exception

Huh?

I haven’t had time to dig further into this, but I’d definitely be interested in hearing some opinions.

Comments

Leave a response

Avatar
retsoced Comment_bubble about 23 hours later:
Maybe you should expect the unexcepted? gah... bad pun.....
Avatar
a silent rogue Comment_bubble 1 day later:
My first guess would be that when you type in just a single identifier, in this case, a typo'd rolename, it cannot distinguish whether you are specifying a rolename or a domainname. By default, it checks rolenames in the default domain. When it doesn't find any, I think it is assuming you meant a domain, so it tries and fails to connect to a domain with name of typorolename. Perhaps if it cannot connect to the domain, it assumes it is because it does not have a trust relationship, rather than the fact that the domain doesn't exist.
Avatar
Ryan Baxter Comment_bubble 1 day later:
a silent rogue - Your explanation does make sense given the results of my test case. I suppose sometimes True or False just isn't enough. :)