2015-09-11 174 views
0

我在做一個簡單的網站來了解關於asp.net/AD認證。ASP.NET Active Directory自動登錄

我使用了本教程中的一些代碼片段:https://support.microsoft.com/en-us/kb/316748,通過登錄頁面成功使用帶有表單身份驗證的AD。我使用這些IIS身份驗證設置的網站:

Anonymous Authentication -Enabled 
ASP.NET Impersonation  -Disabled 
Basic Authentication  -Disabled 
Digest Authentication  -Disabled 
Forms Authentication  -Enabled 
Windows Authentication  -Disabled 

我想使用的憑據當前登錄的Windows用戶,要麼不及時或僅如果失敗提示。當我將Web.config身份驗證模式更改爲「Windows」並將IIS設置更改爲如下所示時,它具有彈出式憑據提示符,但只是保持提示並且從不接受憑據。

Anonymous Authentication -Enabled 
ASP.NET Impersonation  -Disabled 
Basic Authentication  -Disabled 
Digest Authentication  -Disabled 
Forms Authentication  -Disabled 
Windows Authentication  -Enabled 

我試過其他幾種組合,但都失敗了。

本網站的所有文件:

LdapAuthentication.cs - is in App_Code and is a direct copy/paste from the tutorial 
Logon.aspx - is copy/pasted from the tutorial with the companies LDAP path added 
Default.aspx - is a direct copy/paste from the WebForm1.aspx in the tutorial 
Web.config (shown below) 

<?xml version="1.0" encoding="UTF-8"?> 
<configuration> 
    <system.web> 
    <compilation debug="true" targetFramework="4.5"> 
     <assemblies> 
     <add assembly="System.DirectoryServices, Version=4.0.0.0, Culture=neutral, PublicKeyToken=B03F5F7F11D50A3A" /> 
     </assemblies> 
    </compilation> 
    <httpRuntime targetFramework="4.5" /> 
    <authentication mode="Forms"> <!-- I also tried "Windows" --> 
     <forms loginUrl="logon.aspx" name="adAuthCookie" timeout="10" path="/" /> 
    </authentication> 
    <authorization> 
     <deny users="?" /> 
     <allow users="*" /> 
    </authorization> 
    <identity impersonate="true" /> 
    <anonymousIdentification enabled="false" /> 
    </system.web> 
    <system.webServer> 
    <validation validateIntegratedModeConfiguration="false" /> 
    </system.webServer> 
</configuration> 
+0

看看使用'PrincipalContext'很少'AD沿code'我目前使用它,這是一個生命的救星,如果你想只是不自動登錄或驗證,以允許用戶輸入網頁,如果他們在域中..只使用'PrincipalContext'非常簡單,只能做2到3行代碼 – MethodMan

+1

嘗試從web.config中刪除表單身份驗證元素,因爲您不會將它用於集成Windows驗證。 – mason

回答

0

確保IIS是正確配置爲使用ActiveDirectory的認證與形式,它的工作原理與Visual Studio的本地服務器,但不是在IIS。 在IIS 7+中,它是應用程序池帳戶。 - 只需創建一個在該帳戶下運行的新應用程序池,並將該應用程序池分配給您的應用程序/站點。 - 右鍵單擊​​新池(示例ASP.NET V4.0 Mypool) - >高級設置 - 在Process model中,選擇LocalSystem作爲Identity。 Web.config文件:

<system.web> 
<compilation targetFramework="4.0" debug="true"/> 
.......... 
<authentication mode="Forms"> 
     <forms loginUrl="login.aspx" name="adAuthCookie" timeout="10" path="/"/> 
    </authentication>  
    <identity impersonate="false"/> 
    <authorization> 
     <deny users="?"/> 
     <allow users="*"/> 
    </authorization> 
</system.web> 
相關問題