views:

329

answers:

1

Using the ActiveDirectory Provider, when i'm execute the Membershhip.GetUser() i got the following error massage saying: "The parameter 'username' must not be empty.".

Here is the membership configuration:

<membership defaultProvider="AspNetActiveDirectoryMembershipProvider" >
  <providers>
    <clear/>
    <add name="AspNetActiveDirectoryMembershipProvider"
         type="System.Web.Security.ActiveDirectoryMembershipProvider, System.Web, Version=2.0.3600.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
         connectionStringName="ADConnectionString"
         attributeMapUsername="sAMAccountName"/>
  </providers>
</membership>
<authentication mode="Windows"/>
<authorization>
  <deny users="?"/>
  <allow users="*"/>
</authorization>

I'm trying to access this method from Visual studio unit test method. Thanks for any help :)

+1  A: 

The problem was that the current thread principal has not been set. Adding the follwing row: Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
is initialize the current principlal and the GetUser() is back to work.

Tamir