AD Provider Membership.GetUser() 导致错误:“参数‘用户名’; 不能为空。”
当我执行 Membershhip.GetUser()
时,使用 ActiveDirectory Provider 我收到一条错误消息:
参数“用户名”不能为空。
这是成员资格配置:
<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 单元测试方法访问此方法。 谢谢你的帮助 :)
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 :)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
问题是当前线程主体尚未设置。
添加以下行:
Thread.CurrentPrincipal = new WindowsPrincipal(WindowsIdentity.GetCurrent());
正在初始化当前主体,并且 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.