![](/img/trans.png)
[英]ASP.NET / Active Directory - Supporting auto login for domain users
[英]ASP.NET Active Directory Auto-Login
我正在制作一個簡單的網站,以了解asp.net/AD身份驗證。
我使用了本教程中的一些代碼段: https : //support.microsoft.com/zh-cn/kb/316748 ,可以從登錄頁面成功將AD與Forms Authentication一起使用。 我將以下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>
確保IIS已正確配置為對表單使用ActiveDirectory身份驗證,它可與Visual Studio中的本地服務器一起使用,但不適用於IIS。 在IIS 7+中,它是應用程序池帳戶。 -只需創建一個在該帳戶下運行的新應用程序池,然后將該應用程序池分配給您的應用程序/站點。 -右鍵單擊新池(例如ASP.NET V4.0 Mypool)->高級設置-在“進程”模型中,選擇“本地系統”作為“標識”。 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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.