簡體   English   中英

如何允許我的Azure Web應用程序訪問Active Directory?

[英]How to allow my Azure web application to access Active Directory?

我有一個使用Active Directory進行身份驗證和授權的WebForms應用程序。 它在localhost上正常工作,但是一旦發布到Azure后嘗試訪問該站點時失敗。 我確保該應用程序已在Azure Active Directory中注冊。 如果我不嘗試獲取當前用戶的AD安全組,則該應用程序將啟動並正常運行。 這是引起問題的網站管理員的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?

請注意,Azure AD!= Windows AD。 從代碼看來,您的應用似乎正在訪問本地Windows AD。 因此,當您使用Azure時,基本上有兩個選擇:1)使用Azure AD API進行身份驗證並獲取用戶信息2)您可以擁有一個單獨的運行Windows AD的Windows VM,然后您的Azure Web App可以訪問它。

如果我是你,我會探索第一個選擇。 希望能幫助到你

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM