vb.net 无法在 ASP.NET VB 站点中加载 System.DirectoryServices.AccountManagement
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/25917186/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot load System.DirectoryServices.AccountManagement in ASP.NET VB site
提问by justanotherguy
I have been working on adding Active Directory functionality to an already existing ASP.NET website following this guide by Microsoft: http://support.microsoft.com/kb/326340. It's been a long process, but what I'm stuck on now is not being able to access the AccountManagement class to use certain functions such as "GetGroup()".
我一直致力于按照 Microsoft 的本指南将 Active Directory 功能添加到现有的 ASP.NET 网站:http: //support.microsoft.com/kb/326340。这是一个漫长的过程,但我现在遇到的问题是无法访问 AccountManagement 类来使用某些函数,例如“GetGroup()”。
I can access DirectoryServices just fine, but not Account Management. When I use the following code to test the reference:
我可以很好地访问 DirectoryServices,但不能访问帐户管理。当我使用以下代码来测试参考时:
Response.Write(System.DirectoryServices.AccountManagement.Principal.GetGroups())
I get this error: BC30456: 'AccountManagement' is not a member of 'DirectoryServices'.
我收到此错误:BC30456:“AccountManagement”不是“DirectoryServices”的成员。
I have already added this assembly tag to the web.config page:
我已经将此程序集标记添加到 web.config 页面:
<add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" />
Also I am importing both namespaces:
此外,我正在导入两个命名空间:
<%@ Import Namespace="System.DirectoryServices" %>
<%@ Import Namespace="System.DirectoryServices.AccountManagement" %>
And this is my version info that shows on the error page:
这是我在错误页面上显示的版本信息:
Version Information: Microsoft .NET Framework Version:4.0.30319; ASP.NET Version:4.0.30319.34237
版本信息:Microsoft .NET Framework 版本:4.0.30319;ASP.NET 版本:4.0.30319.34237
I'm editing this website in VS 2010. What am I missing and how can I get AccountManagement added here? Am I not importing it properly, or is there somewhere I can check to see if there is a missing .dll?
我正在 VS 2010 中编辑此网站。我缺少什么以及如何在此处添加 AccountManagement?是我没有正确导入它,还是有什么地方可以检查是否缺少 .dll?
采纳答案by Reg Edit
Although you're importing both namespaces in the markup, you only reference System.DirectoryServices.dll. The AccountManagement part is in a separate dll.
尽管您在标记中导入了两个命名空间,但您只引用了System.DirectoryServices.dll. AccountManagement 部分位于单独的 dll 中。
Add another reference to web.config:
添加对 web.config 的另一个引用:
<add assembly="System.DirectoryServices.AccountManagement ...
回答by Rolo
I tried as suggested by Reg Edit, but then I had another error in which my application couldn't find the reference described in the web.config. After a few hours, I came across this stackoverflow answer.
我按照 Reg Edit 的建议进行了尝试,但随后出现了另一个错误,其中我的应用程序找不到 web.config 中描述的引用。几个小时后,我遇到了这个 stackoverflow answer。
It says that the reference to System.DirectoryServices.AccountManagementshould have "Copy local" on 'True'. Honestly, I see no reason why that should work, because that is a Framework library, but changing that setting worked for me.
它说对System.DirectoryServices.AccountManagement的引用应该在“ True”上具有“复制本地” 。老实说,我认为没有理由这样做,因为这是一个框架库,但更改该设置对我有用。
You can do something like this:
using (var context = new PrincipalContext(ContextType.Domain)) { var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name); var firstName = principal.GivenName; var lastName = principal.Surname; }You'll need to add a reference to the
System.DirectoryServices.AccountManagementassembly.You can add a Razor helper like so:
@helper AccountName() { using (var context = new PrincipalContext(ContextType.Domain)) { var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name); @principal.GivenName @principal.Surname } }If you indend on doing this from the view, rather than the controller, you need to add an assembly reference to your web.config as well:
<add assembly="System.DirectoryServices.AccountManagement" />Add that under
configuration/system.web/assemblies.
你可以这样做:
using (var context = new PrincipalContext(ContextType.Domain)) { var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name); var firstName = principal.GivenName; var lastName = principal.Surname; }您需要添加对
System.DirectoryServices.AccountManagement程序集的引用 。你可以像这样添加一个 Razor 助手:
@helper AccountName() { using (var context = new PrincipalContext(ContextType.Domain)) { var principal = UserPrincipal.FindByIdentity(context, User.Identity.Name); @principal.GivenName @principal.Surname } }如果您打算从视图而不是控制器执行此操作,则还需要向您的 web.config 添加程序集引用:
<add assembly="System.DirectoryServices.AccountManagement" />在
configuration/system.web/assemblies.
From: Answer To: How do I get the full name of a user in .net MVC 3 intranet app?

