简体   繁体   English

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

[英]Can't login to website using windows authentication IIS

I've been searching for a solution for this headache for a quite long.很长一段时间以来,我一直在寻找解决这个头痛问题的方法。

I have a website that I want to deploy to my web server, so I'm using IIS 7 and followed these steps to authenticate logging into it:我有一个要部署到 Web 服务器的网站,因此我使用的是 IIS 7 并按照以下步骤对登录进行身份验证:

1- Open IIS 1-打开IIS

2- Add Website (with random port number) 2- 添加网站(带有随机端口号)

3- Set the application pool for it to a specific Identity 3- 将其应用程序池设置为特定身份

4- Disable Anonymous authentication then enable Windows Authentication. 4- 禁用匿名身份验证,然后启用 Windows 身份验证。

5- Remove "Allow All users" rule 5- 删除“允许所有用户”规则

6- Add allow rule for an admin user and give him full control access 6-为管理员用户添加允许规则并授予他完全控制访问权限

When I try to access it it asks for a username and password which must be the same user as the one added in step 6 .当我尝试访问它时,它要求输入用户名和密码,该用户名和密码必须与步骤 6 中添加的用户相同。

The problem is whenever I click ok the logging window keeps popping up and can't access the website as a result问题是每当我单击“确定”时,日志记录窗口都会不断弹出,因此无法访问该网站

I also tried to add deny rule for anonymous users我还尝试为匿名用户添加拒绝规则

Is there anything must be added to web.config file or something ?是否必须将任何内容添加到 web.config 文件或其他内容? Do I need to install something or disable something ?我需要安装某些东西或禁用某些东西吗?

Any suggestion is very appreciated任何建议都非常感谢

EDIT This is my web.config file authorization section编辑这是我的 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>

After spending hours trying to solve this finally I figured out the solution在花了几个小时试图解决这个问题后,我终于找到了解决方案

1- Open IIS 1-打开IIS

2- Add Website (with random port number) 2- 添加网站(带有随机端口号)

3- Set the application pool for it to a specific Identity 3- 将其应用程序池设置为特定身份

4- Disable Anonymous authentication then enable Windows Authentication. 4- 禁用匿名身份验证,然后启用 Windows 身份验证。

5- Remove "Allow All users" rule 5- 删除“允许所有用户”规则

6- Add allow rule for an admin user and give him full control access 6-为管理员用户添加允许规则并授予他完全控制访问权限

Note: all previous steps were made using IIS wizard注意:之前的所有步骤都是使用 IIS 向导完成的

7- After openinig web.config file I can't find any changes after adding allow rules so, I had to do it manually by adding <authorization> tag then adding these rules in the same order (this order is very important either it won't work) 7- openinig web.config 文件后,我在添加允许规则后找不到任何更改,因此,我必须通过添加<authorization>标记手动执行此操作,然后以相同的顺序添加这些规则(此顺序非常重要,无论它赢得不工作)

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

From MSDN , you need to enable windows authentication both in IIS and ASP.NET application:MSDN ,您需要启用在IIS和ASP.NET应用程序Windows身份验证:

Start Internet Information Services (IIS).启动 Internet 信息服务 (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.确保未选中匿名访问复选框,并且集成 Windows 身份验证是唯一选中的复选框。

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.在应用程序的 Web.config 文件或机器级 Web.config 文件中,确保身份验证模式设置为 Windows,如下所示。

...
 <system.web>
  ...
  <authentication mode="Windows"/>
  ...
 </system.web>
  • Enabling windows authentication on IIS so that IIS authenticates the user.在 IIS 上启用 Windows 身份验证,以便 IIS 对用户进行身份验证。
  • Adding a setting to your web.config so that ASP.NET knows what authentication provider to use.向您的 web.config 添加设置,以便 ASP.NET 知道要使用的身份验证提供程序。 In this case, ASP.NET uses windows authentication provider to set the value of the current User property to a WindowsIdentity based on the credentials supplied by IIS .在这种情况下,ASP.NET 使用 Windows 身份验证提供程序根据 IIS 提供的凭据将当前用户属性的值设置为 WindowsIdentity。

Also check for authorization:还要检查授权:

The rules are checked from top to bottom and stopped at first matching rule .从上到下检查规则并在第一个匹配规则处停止。 Therefore, you should specify allow before deny .因此,您应该deny之前指定allow Example:例子:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM