我在做一个简单的网站来了解关于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>
看看使用'PrincipalContext'很少'AD沿code'我目前使用它,这是一个生命的救星,如果你想只是不自动登录或验证,以允许用户输入网页,如果他们在域中..只使用'PrincipalContext'非常简单,只能做2到3行代码 – MethodMan
尝试从web.config中删除表单身份验证元素,因为您不会将它用于集成Windows验证。 – mason