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

.NET Core 6 Azure应用用MS Auth登录时遇HttpListenerException访问被拒

.NET Core 6 Azure应用服务MS Auth登录HttpListener访问被拒问题解决

错误详情

触发登录时出现如下错误:
An HttpListenerException occurred while listening on http://localhost:49299/ for the system browser to complete the login. Possible cause and mitigation: the app is unable to listen on the specified URL; run 'netsh http add iplisten 127.0.0.1' from the Admin command prompt. Access is denied.

解决方案

1. 排查端口占用情况

执行命令检查目标端口是否被其他进程占用:

netstat -ano | findstr :49299

若返回结果,记录对应的PID,打开任务管理器结束该进程后重试登录流程。

2. 重新配置HTTP监听权限(需管理员权限)

  • 先删除原有监听配置:
    netsh http delete iplisten ipaddress=127.0.0.1
    
  • 重新添加本地回环地址监听:
    netsh http add iplisten ipaddress=127.0.0.1
    
  • 给当前用户分配目标URL的监听权限,替换[你的用户名]为实际Windows用户名(格式:机器名\用户名):
    netsh http add urlacl url=http://localhost:49299/ user=[你的用户名]
    

3. 修正MS Auth配置(适配Azure应用服务场景)

  • 确保appsettings.json中的Azure AD配置正确:
    "AzureAd": {
      "Instance": "https://login.microsoftonline.com/",
      "Domain": "your-domain.onmicrosoft.com",
      "TenantId": "你的租户ID",
      "ClientId": "你的应用注册ClientID",
      "CallbackPath": "/signin-oidc",
      "ClientSecret": "你的应用注册密钥"
    }
    
  • 登录Azure门户,进入对应应用注册,在重定向URI中同时添加本地调试地址(如https://localhost:49299/signin-oidc)和Azure应用服务地址(如https://你的应用名.azurewebsites.net/signin-oidc)。

4. 重启HTTP相关服务

  • 打开服务管理器(运行services.msc),找到HTTP Service和HTTP SSL服务,依次重启。
  • 或使用命令行(管理员权限):
    net stop http
    net start http
    
    注意:此操作会停止依赖HTTP服务的其他进程(如IIS),完成后需按需重启相关服务。

内容的提问来源于stack exchange,提问作者Amit Sharma

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.28 16:10:19