【问题标题】:While trying to retrieve the authorization groups, an error (5) occurred尝试检索授权组时,发生错误 (5)
【发布时间】:2011-04-28 06:32:21
【问题描述】:

如果我在服务器上而不是在本地运行应用程序,就会出现此错误。为什么这发生在服务器上而不是本地???

List<GroupPrincipal> result = new List<GroupPrincipal>();

// establish domain context
PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain);

// find your user
UserPrincipal user = UserPrincipal.FindByIdentity(yourDomain, userName);

// if found - grab its groups
if (user != null)
{
//here happens the error on server.
PrincipalSearchResult<Principal> groups = user.GetAuthorizationGroups();

请帮帮我。

堆栈跟踪:

   [PrincipalOperationException: While trying to retrieve the authorization groups, an error (5) occurred.]
   System.DirectoryServices.AccountManagement.AuthZSet..ctor(Byte[] userSid, NetCred credentials, ContextOptions contextOptions, String flatUserAuthority, StoreCtx userStoreCtx, Object userCtxBase) +317263
   System.DirectoryServices.AccountManagement.ADStoreCtx.GetGroupsMemberOfAZ(Principal p) +441
   System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroupsHelper() +78
   System.DirectoryServices.AccountManagement.UserPrincipal.GetAuthorizationGroups() +11
   IntegrationApp.App_Code.ActiveDir.GetGroups(String userName) in C:\Documents and Settings\mta\My Documents\IntegrationApp\IntegrationApp\App_Code\3-Tier\DAL\ActiveDir.cs:54
   IntegrationApp.App_Code._3_Tier.BAL.DatabaseBAL.BepaalDefaultNiveau2(String melder) in C:\Documents and Settings\mta\My Documents\IntegrationApp\IntegrationApp\App_Code\3-Tier\BAL\DatabaseBAL.cs:75
   IntegrationApp.Detailscherm.VulLijsten() in C:\Documents and Settings\mta\My Documents\IntegrationApp\IntegrationApp\Detailscherm.aspx.cs:89
   IntegrationApp.Detailscherm.Page_Load(Object sender, EventArgs e) in C:\Documents and Settings\mta\My Documents\IntegrationApp\IntegrationApp\Detailscherm.aspx.cs:30
   System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o, Object t, EventArgs e) +25
   System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +42
   System.Web.UI.Control.OnLoad(EventArgs e) +132
   System.Web.UI.Control.LoadRecursive() +66
   System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +2428

【问题讨论】:

  • 请添加更多上下文。什么样的应用程序,它在哪里失败,你得到什么错误信息?添加一些代码。
  • 错误信息+堆栈跟踪是什么?

标签: c# asp.net active-directory


【解决方案1】:

我找到了另一种访问 GROUPS 的解决方案:

PrincipalSearchResult<Principal> groups = user.GetGroups();

【讨论】:

  • user.GetGroups() 和 user.GetAuthorizationGroups() 真的不是一回事吗?
  • GetGroups 没有导致类似GetAuthorizationGroups 的错误,但没有返回GetAuthorizationGroups 所做的完整组列表。
【解决方案2】:

您的进程在服务器上以什么身份运行?很可能,该用户没有正确的权限来访问您的 Active Directory。

你能测试它是否适用于 PrincipalContext 的构造函数吗?

PrincipalContext yourDomain = new PrincipalContext(ContextType.Domain, "MY.DOMAIN.HERE", "USERNAME", "PASSWORD");

如果可行,您可能希望创建一个专用域用户供您的应用在其下运行。

【讨论】:

    【解决方案3】:

    我发现执行 GetAuthorizationGroups 需要 Windows 授权访问组的成员身份。

    请参阅以下文章: http://support.microsoft.com/kb/331951

    【讨论】:

    • 这是个好主意吗?我的意思是在帐户的活动目录中授予提升的权限?
    【解决方案4】:

    只是一个猜测,但这听起来像是信任级别的问题。看看这里包含的信息是否有帮助:

    您是在您的机器上以管理员身份运行它,还是在服务器上以更受限的帐户运行它?

    如果是这样,我会尝试在服务器上以完全信任的方式运行它(如果可以的话),看看问题是否消失。

    【讨论】:

    • 这是我的问题。可以通过在web.config 中设置信任级别并在本地计算机(&lt;system.web&gt;&lt;trust level="Medium"/&gt;&lt;/system.web&gt;)上运行来测试它。这很可能会给出与在您的服务器上运行时相同的结果。注意。您无法使用此方法将 Web 服务器设置为完全信任。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-05-24
    • 2017-01-19
    • 2012-09-18
    • 1970-01-01
    • 2019-04-15
    • 2020-12-31
    相关资源
    最近更新 更多