【发布时间】:2018-10-09 15:56:17
【问题描述】:
我有一个使用 Active Directory 进行身份验证和授权的 WebForms 应用程序。它在 localhost 上工作得很好,但是当我尝试访问发布到 Azure 的站点时失败。我已确保该应用程序已在 Azure Active Directory 中注册。如果我不尝试获取当前用户的 AD 安全组,该应用程序将按预期启动并运行。以下是导致问题的 Site Master 的 Page_Load 事件中的代码:
protected void Page_Load(object sender, EventArgs e)
{
PrincipalSearchResult<Principal> groups = UserPrincipal.Current.GetAuthorizationGroups();
IEnumerable<string> groupNames = groups.Select(x => x.Name);
if (HttpContext.Current.User.Identity.IsAuthenticated)
{
HyperLink newphaud = LIV.FindControl("liaNewPhaud") as HyperLink;
HtmlGenericControl liadmin = LIV.FindControl("navAdminsDdl") as HtmlGenericControl;
newphaud.Visible = (groupNames.Contains("SG1") || groupNames.Contains("SG2"));
liadmin.Visible = groupNames.Contains("SG1");
}
}
以下是异常详情:
System.Runtime.InteropServices.COMException:访问被拒绝。
这是堆栈跟踪:
[COMException (0x80070005): Access is denied.
]
System.DirectoryServices.DirectoryEntry.Bind(Boolean throwIfFail) +399115
System.DirectoryServices.DirectoryEntry.Bind() +36
System.DirectoryServices.DirectoryEntry.RefreshCache() +45
System.DirectoryServices.AccountManagement.PrincipalContext.DoMachineInit() +211
System.DirectoryServices.AccountManagement.PrincipalContext.Initialize() +128
System.DirectoryServices.AccountManagement.PrincipalContext.get_QueryCtx() +31
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithTypeHelper(PrincipalContext context, Type principalType, Nullable`1 identityType, String identityValue, DateTime refDate) +14
System.DirectoryServices.AccountManagement.Principal.FindByIdentityWithType(PrincipalContext context, Type principalType, IdentityType identityType, String identityValue) +90
System.DirectoryServices.AccountManagement.UserPrincipal.FindByIdentity(PrincipalContext context, IdentityType identityType, String identityValue) +32
System.DirectoryServices.AccountManagement.UserPrincipal.get_Current() +191
phaud.SiteMaster.Page_Load(Object sender, EventArgs e) in C:\Users\user1\source\repos\phaud\phaud\Site.Master.cs:19
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender, EventArgs e) +51
System.Web.UI.Control.OnLoad(EventArgs e) +95
System.Web.UI.Control.LoadRecursive() +59
System.Web.UI.Control.LoadRecursive() +131
System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) +678
我需要做什么才能让我的 Azure Web 应用访问 AD?
【问题讨论】:
标签: asp.net azure active-directory