为什么集成 Windows 身份验证不起作用?

Why isn't Integrated Windows Authentication working?

我使用 Web API 模板 创建了一个新的 ASP.NET MVC 应用程序。我在创建项目时选择的认证方式为“Windows认证

我在 web.config:

中添加了 windows 身份验证
  <system.web>
    <authentication mode="Windows" />
  </system.web>

我确保 Windows 身份验证 安装在 IISenabled 在 IIS 中的同一 Web 应用程序中。

我创建了一个显示用户用户名的控制器操作:

public JsonResult Login()
{
    string userName = System.Web.HttpContext.Current.User.Identity.Name;
    string message = String.Format("Welcome, {0}!", userName);
    return Json(userName, JsonRequestBehavior.AllowGet);
}

当我在浏览器中访问此 URL 时,系统不会提示用户输入凭据并且返回的值为空字符串。

我错过了什么?

您必须在 IIS 管理控制台中为您的站点停用 Anonymous Authentication 并激活 Windows Authentication