ASP.NET Active Directory自动登录

时间:2015-09-11 21:50:50

标签: c# asp.net authentication iis active-directory

我正在创建一个简单的网站来了解asp.net/AD身份验证。

我使用了本教程中的一些代码段:https://support.microsoft.com/en-us/kb/316748从登录页面成功使用AD和Forms身份验证。我为网站使用这些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>

1 个答案:

答案 0 :(得分:0)

确保IIS已正确配置为使用ActiveDirectory身份验证与表单,它适用于Visual Studio中的本地服务器,但不适用于IIS。 在IIS 7+中,它是应用程序池帐户。 - 只需创建一个在该帐户下运行的新应用程序池,并将该应用程序池分配给您的应用程序/站点。 - 右键单击​​新池(示例ASP.NET V4.0 Mypool) - &gt;高级设置 - 在Process model中,选择LocalSystem作为Identity。 web.config中:

'SQL Server Native Client 11.0SQLHOST'