簡體   English   中英

具有Windows身份驗證aganst Active Directory的Asp.net WebPage

[英]Asp.net WebPage with Windows Authentication aganst Active Directory

我整晚都在搞砸,這實在令人沮喪。 我最終顯示了該網頁,但是由於某種原因它無法正常工作,這意味着它使我回到錯誤頁面並指出“無法驗證用戶身份,請重試!”。 我無法弄清楚這一點,因為它可以在安裝了Visual Studio的本地計算機上完美找到。

如果有人花時間幫助解決這個問題,請全天為之奮斗。 謝謝

Class.cs

public bool IsUserInSetup(string groupName, UserPrincipal user)
    {
        PrincipalContext context = new PrincipalContext(ContextType.Domain, "DomainName");
       GroupPrincipal group = GroupPrincipal.FindByIdentity(context, "GroupName");

        if (user.IsMemberOf(group))
        {
            return true;
        }
        return false;
    }

Authentication.aspx.cs

 if (!IsPostBack)
            {
                if (Request.IsAuthenticated)
                {

                    if (gv.IsUserInSetup("GroupName", user))
                    {
                        Session["userValue"] = UserPrincipal.Current;

                        Response.Redirect("Default.aspx");

                    }
 else
                {
                    lblInfo.Text = "Could Not Authenticate User Please Try Again!";
                    lblInfo.Text += "<br><b>Name: </b>" + User.Identity.Name;
                    lblInfo.Text += "<br><b>Authenticated With: </b>";
                    lblInfo.Text += User.Identity.AuthenticationType;
                }

應用程序在IIS上部署時可能失敗的一種可能原因是,您將其配置為在其下運行的帳戶沒有足夠的特權來訪問Active Directory服務器。 默認情況下,IIS中的應用程序池在服務器帳戶本地的內置ApplicationPoolIdentity帳戶下運行。 您應該轉到IIS中應用程序池的設置,然后選擇具有足夠特權的域帳戶。

在VS中本地運行時,此方法有效,因為您使用自己的帳戶運行應用程序,該帳戶可能是有權訪問Active Directory的域帳戶。

在另一個論壇上得到了答案,但是我無緣無故地做了很多額外的工作。 Asp.net有一個USER.ISINROLE(“ GROUPNAME”),我使用了它。

暫無
暫無

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

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