You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

ASP.NET Core 7通过IIS Express运行时反复要求Windows凭据的解决方法

解决ASP.NET Core 7 + IIS Express自动Windows身份验证问题

以下是针对重复输入域凭据问题的有效排查和解决步骤:

1. 确认浏览器自动登录配置

  • Chrome/Edge:在地址栏输入chrome://settings/content/automaticPasswords(Edge为edge://settings/content/automaticPasswords),确保「自动登录」已开启。
  • 配置浏览器本地Intranet区域:
    1. 打开浏览器设置 → 隐私和安全性 → 安全性 → 本地Intranet → 站点
    2. 添加https://localhost及你使用的开发端口(如https://localhost:5001)
    3. 勾选「自动登录到Intranet区域中的所有站点」

2. 修正applicationhost.config的Windows Auth配置

确保解决方案根目录下.vs\[解决方案名]\config\applicationhost.config(优先使用项目本地配置,而非全局IIS Express配置)中的身份验证节点正确:

<authentication>
  <windowsAuthentication enabled="true">
    <providers>
      <add value="Negotiate" />
      <add value="NTLM" />
    </providers>
  </windowsAuthentication>
  <anonymousAuthentication enabled="false" />
</authentication>

修改后重启Visual Studio,避免配置未生效。

3. 验证launchSettings.json完整配置

确保launchSettings.json中IIS Express的配置无冲突:

"IIS Express": {
  "commandName": "IISExpress",
  "launchBrowser": true,
  "environmentVariables": {
    "ASPNETCORE_ENVIRONMENT": "Development"
  },
  "windowsAuthentication": true,
  "anonymousAuthentication": false,
  "sslPort": 44300 // 替换为你的实际SSL端口
}

4. 检查ASP.NET Core服务配置

在Program.cs中确认身份验证中间件顺序正确:

var builder = WebApplication.CreateBuilder(args);

// 添加Windows身份验证服务
builder.Services.AddAuthentication(IISDefaults.AuthenticationScheme);

var app = builder.Build();

// 中间件顺序不能颠倒
app.UseAuthentication();
app.UseAuthorization();

app.MapControllers();
app.Run();

5. 排查协议与运行身份问题

  • 确认开发机器已加入域,且Visual Studio以当前域账户运行(右键Visual Studio → 以管理员身份运行,检查账户身份)
  • 若Kerberos协商失败,可在applicationhost.config的windowsAuthentication节点添加:
    <windowsAuthentication enabled="true" useKernelMode="true" authPersistSingleRequest="true">
    

6. 清除缓存与旧凭据

  • 清除浏览器缓存、Cookie及保存的localhost相关凭据
  • 打开Windows凭据管理器(控制面板 → 用户账户 → 凭据管理器),删除所有与localhost有关的存储凭据

若以上步骤无效,可尝试卸载重装IIS Express,或重置Visual Studio开发环境(工具 → 导入和导出设置 → 重置所有设置)

内容的提问来源于stack exchange,提问作者Jan Drozen

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.15 14:16:06