AD提供Membership.GetUser()原因错误说:"参数“用户名”不能为空" [英] AD Provider Membership.GetUser() cause error saying: "The parameter 'username' must not be empty."
问题描述
使用ActiveDirectory中提供,当我执行 Membershhip.GetUser()
我得到一个错误信息:
Using the ActiveDirectory Provider, when I execute Membershhip.GetUser()
i get an error message:
参数用户名不能为空。
下面是成员的配置:
<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>
我试图访问从Visual Studio单元测试方法这个方法。 感谢您的帮助:)
I'm trying to access this method from Visual studio unit test method. Thanks for any help :)
推荐答案
但问题是,当前线程主体尚未确定。
添加follwing行:
= Thread.CurrentPrincipal中新的WindowsPrincipal(WindowsIdentity.GetCurrent());
是初始化当前principlal和的getUser()是回去工作了。
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.
这篇关于AD提供Membership.GetUser()原因错误说:&QUOT;参数“用户名”不能为空&QUOT;的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!