AD Provider Membership.GetUser() cause error saying: "The parameter 'username' must not be empty."

Go To StackoverFlow.com

0

Using the ActiveDirectory Provider, when I execute Membershhip.GetUser() i get an error message:

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 :)

2009-06-16 08:52
by Tamir
Why are you using the membership provider in a unit test - RichardOD 2009-06-16 08:58
Already solved, thank you - Tamir 2009-06-16 09:58


1

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.

2009-06-16 09:58
by Tamir