无法使用 windows 身份验证 IIS 登录网站

Can't login to website using windows authentication IIS

我一直在寻找解决这个问题的方法。

我有一个要部署到我的 Web 服务器的网站,所以我使用 IIS 7 并按照以下步骤对登录它进行身份验证:

1- 打开 IIS

2- 添加网站(使用随机端口号)

3- 将其应用程序池设置为特定标识

4- 禁用匿名身份验证然后启用 Windows 身份验证。

5- 删除 "Allow All users" 规则

6- 为管理员用户添加允许规则并授予他完全控制权限

当我尝试访问它时,它要求输入用户名和密码,该用户名和密码必须与在第 6 步中添加的用户相同。

问题是每当我单击“确定”时,日志记录 window 不断弹出,结果无法访问该网站

我还尝试为匿名用户添加拒绝规则

是否有任何必须添加到 web.config 文件中的东西?我需要安装或禁用某些东西吗?

非常感谢任何建议

编辑 这是我的 web.config 文件授权部分

<system.web>
  <authentication mode="Windows" />
  <compilation targetFramework="4.5" />
  <httpRuntime targetFramework="4.5" />
  <pages validateRequest="false"></pages>
    <identity impersonate="false" />
  <authorization>
    <allow users="SomeUser" />
    <deny users="*"/>
  </authorization>


</system.web>

MSDN 开始,您需要在 IIS 和 ASP.NET 应用程序中启用 windows 身份验证

Start Internet Information Services (IIS).

Right-click your application's virtual directory, and then click Properties.

Click the Directory Security tab. Under Anonymous access and authentication control, click Edit.

Make sure the Anonymous access check box is not selected and that Integrated Windows authentication is the only selected check box.

In your application's Web.config file or in the machine-level Web.config file, ensure that the authentication mode is set to Windows as shown here.

...
 <system.web>
  ...
  <authentication mode="Windows"/>
  ...
 </system.web>
  • 在 IIS 上启用 windows 身份验证,以便 IIS 对用户进行身份验证。
  • 正在为您的 web.config 添加设置,以便 ASP.NET 知道要使用的身份验证提供程序。在这种情况下,ASP.NET 使用 windows 身份验证提供程序根据 IIS 提供的凭据将当前用户 属性 的值设置为 WindowsIdentity .

还要检查授权:

规则从上到下检查,并在第一个匹配规则处停止。因此,您应该在 deny 之前指定allow 。示例:

<authorization>
  <allow users="John"/>
  <deny users="*"/>
</authorization>

在花了几个小时试图解决这个问题后,我终于找到了解决方案

1- 打开 IIS

2- 添加网站(使用随机端口号)

3- 将其应用程序池设置为特定身份

4- 禁用匿名身份验证然后启用 Windows 身份验证。

5- 删除 "Allow All users" 规则

6- 为管理员用户添加允许规则并授予他完全控制权限

注意:之前的所有步骤都是使用 IIS 向导完成的

7- 在打开 web.config 文件后,我在添加允许规则后找不到任何更改,所以我不得不通过添加 <authorization> 标签手动完成,然后以相同的顺序添加这些规则(这个命令很重要,不然不行)

<authorization>
   <allow users="<the user that you want to give an access>" />
   <deny users="*" /> <!--to deny all other users-->
</authorization>