【问题标题】:Why isn't Integrated Windows Authentication working?为什么集成 Windows 身份验证不起作用?
【发布时间】:2016-11-24 18:47:00
【问题描述】:

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

我在 web.config 中添加了 windows 身份验证

  <system.web>
    <authentication mode="Windows" />
  </system.web>

我确保 Windows 身份验证 已安装在 IIS 上,并在 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 中为此站点停用基本身份验证并激活 Windows 身份验证?
  • @[Dirk Trilsbeek] 啊,你明白了。我忘了禁用匿名身份验证。它现在正在工作。您能否将其发布为答案,以便我接受?

标签: asp.net asp.net-mvc asp.net-web-api windows-authentication


【解决方案1】:

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-03-18
    • 2019-08-04
    • 2019-10-31
    • 2019-04-08
    • 2017-09-24
    • 2023-04-03
    相关资源
    最近更新 更多