簡體   English   中英

帶有Active Directory的ASP.NET:用戶憑據

[英]ASP.NET with Active Directory: User Credentials

我是ASP.NET新手,正在創建內部應用程序(組中的10個用戶將使用該應用程序)。 目標之一是將用戶添加到Active Directory組。 出於審核目的,應用程序用戶應使用自己的憑據進行AD更改(而不是為此目的創建通用ID)。該網站托管在Windows Server 2008 R2 / IIS 7.0上,所有內容都在企業域中。

IIS設置:
應用程序池名稱:UserAppMapping,Integrated,ApplicationPoolIdentity

身份驗證:僅啟用ASP.NET模擬和Windows身份驗證。

VB.NET代碼(我已經刪除了所有錯誤檢查,所以我可以看到實際的錯誤):

Public Sub AddUserToGroup(userId As String, groupName As String, Optional GroupDN As String = "")

        Using (HostingEnvironment.Impersonate())

            Dim domainName As String = "DOM"

            Dim ou = [String].Format(CultureInfo.InvariantCulture, "dc={0},dc=myorg,dc=com", domainName)

            Dim domain = [String].Format(CultureInfo.InvariantCulture, "{0}.myorg.com", domainName)

            Using insPrincipalContext = New PrincipalContext(ContextType.Domain, domain, ou)
                If insPrincipalContext IsNot Nothing Then
                    Dim insGroupPrincipal As GroupPrincipal = GroupPrincipal.FindByIdentity(insPrincipalContext, System.DirectoryServices.AccountManagement.IdentityType.Name, groupName)

                    Dim user As UserPrincipal = UserPrincipal.FindByIdentity(insPrincipalContext, userId)

                    If insGroupPrincipal IsNot Nothing Then
                        'add user to group
                        If user.IsMemberOf(insGroupPrincipal) Then
                            LabelErr.Text = userId + " is already part of " + groupName
                        Else
                            insGroupPrincipal.Members.Add(user)
                            insGroupPrincipal.Save()
                            Label1.Text = "User added successfully"
                        End If
                    Else
                        Label1.Text = "Cannot retrieve information about " + groupName + " from Active Directory"
                    End If
                Else
                    Label1.Text = "Principal Context is Null"
                End If
                insPrincipalContext.Dispose()
            End Using
        End Using
    End Sub

`

問題

一切正常,但是在代碼中遇到以下幾行時:

insGroupPrincipal.Members.Add(用戶)
insGroupPrincipal.Save()

該應用程序提示輸入用戶憑據。 當我了解此函數中的代碼在Windows標識“ IIS APPPOOL \\ UserAppMapping”的上下文中運行時,它將提示輸入可以訪問Active Directory的憑據。 應用程序用戶是否可以修改AD組 (我假設用戶可以直接在AD中修改組) 而無需鍵入額外的憑據?

如果我從代碼中刪除“使用(HostingEnvironment.Impersonate())”,遇到GroupPrincipal.FindByIdentity時,它將立即失敗。

web.config設置為:

身份驗證模式=“ Windows”
身份冒充=“ true”

提前致謝。

請執行下列操作。

  1. 確保將IIS身份驗證設置為Windows Auth = enabled,Anonymous = false。 除web.config外,這是必需的。

步驟2:您需要在AD中具有比ApplicationPoolIndentity更高的權限。

  1. 您需要一個網絡帳戶來執行AD工作。 創建一個新的網絡帳戶,然后在IIS的應用程序池中將其從ApplicationPoolIndentity更改為“自定義帳戶”。 然后輸入新的AD帳戶和密碼。 (我建議使AD帳戶密碼永不過期)

暫無
暫無

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

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