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

南楼画角 提交于 2019-12-11 16:13:25

问题


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


回答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.



来源:https://stackoverflow.com/questions/1000276/ad-provider-membership-getuser-cause-error-saying-the-parameter-username-m

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!