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

如何消除内网IIS部署的ASP.NET Core(.NET7)应用域凭据弹窗?

解决ASP.NET Core (.NET7) Windows身份验证重复弹出凭据弹窗问题

我在公司本地内网的IIS服务器上部署了一个采用Windows身份验证的ASP.NET Core(.NET7)Web应用,URL为http://myWebApp.mydomain.com。使用Chrome浏览器访问时会弹出域凭据输入窗口,输入正确凭据后可正常使用,但清除浏览器缓存后再次访问,弹窗会再次出现。我希望无需通过“Internet选项”将站点添加到本地Intranet区域来解决这个问题。

现有临时解决方法

  • 打开“Internet选项”
  • 切换到“安全”选项卡
  • 选择“本地Intranet”区域
  • 点击“站点”按钮
  • 勾选“自动检测Intranet网络”复选框
  • 点击“高级”按钮
  • 在“将该网站添加到区域”输入框中填入应用URL并点击“添加”
  • 依次点击“关闭”“确定”保存设置

当前配置文件

web.config配置

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <location path="." inheritInChildApplications="false">
    <system.webServer>
      <security>
        <authentication>
          <anonymousAuthentication enabled="false" />
          <windowsAuthentication enabled="true" />
        </authentication>
      </security>
      <handlers>
        <add name="aspNetCore" path="*" verb="*" modules="AspNetCoreModuleV2" resourceType="Unspecified" />
      </handlers>
      <aspNetCore processPath="dotnet" arguments=".\AuthTest.dll" stdoutLogEnabled="false" stdoutLogFile=".\logs\stdout" hostingModel="inprocess" />
    </system.webServer>
  </location>
</configuration>

Program.cs代码

using Microsoft.AspNetCore.Authentication.Negotiate;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
builder.Services.AddControllersWithViews();

builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
   .AddNegotiate();

builder.Services.AddAuthorization(options =>
{
    // By default, all incoming requests will be authorized according to the default policy.
    options.FallbackPolicy = options.DefaultPolicy;
});
builder.Services.AddRazorPages();

var app = builder.Build();

// Configure the HTTP request pipeline.
if (!app.Environment.IsDevelopment())
{
    app.UseExceptionHandler("/Home/Error");
    // The default HSTS value is 30 days. You may want to change this for production scenarios, see https://aka.ms/aspnetcore-hsts.
    app.UseHsts();
}

app.UseHttpsRedirection();
app.UseStaticFiles();

app.UseRouting();

app.UseAuthorization();

解决方案

1. 配置Kerberos服务主体名称(SPN)

NTLM身份验证需要手动输入凭据,而Kerberos支持自动传递域凭据。以域管理员身份运行命令提示符,为应用程序池账户注册SPN:

setspn -A HTTP/myWebApp.mydomain.com DOMAIN\IISAppPoolUser
setspn -A HTTP/myWebApp DOMAIN\IISAppPoolUser

替换DOMAIN\IISAppPoolUser为运行应用程序池的域账户。

2. 强制ASP.NET Core使用Kerberos

修改Program.cs中的Negotiate配置,指定Kerberos参数:

builder.Services.AddAuthentication(NegotiateDefaults.AuthenticationScheme)
    .AddNegotiate(options =>
    {
        options.KerberosSettings.Domain = "mydomain.com";
        options.KerberosSettings.Spns.Add("HTTP/myWebApp.mydomain.com");
    });

3. 调整IIS身份验证提供程序顺序

  • 打开IIS管理器,定位到目标站点
  • 进入“身份验证”功能,右键“Windows身份验证” → 选择“提供程序”
  • 将Negotiate移到NTLM之前,确保优先使用Kerberos

4. 配置Chrome自动传递凭据

修改Chrome快捷方式,添加白名单参数实现自动凭据传递:

  • 右键Chrome快捷方式 → 属性
  • 在“目标”输入框末尾添加(注意前面加空格):
    --auth-server-whitelist="*.mydomain.com"
    
  • 保存后重启Chrome

5. 验证应用程序池权限

确保运行应用程序池的域账户具备:

  • Web应用目录的读取权限
  • 域内的委派权限(若应用需要跨服务器访问资源)

内容的提问来源于stack exchange,提问作者Kyle Jamieson

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.16 08:17:40