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

ASP.NET项目切换本地IP替代localhost配置失效求助(JetBrains IDE)

解决ASP.NET项目绑定本地IP后配置被覆盖的问题

核心原因

直接修改applicationhost.config会被JetBrains IDE(如Rider)自动覆盖,因为该文件是IDE根据项目配置动态生成的,需从项目自身配置入手。

解决步骤

  • 修改项目的launchSettings.json配置
    找到项目根目录下Properties文件夹中的launchSettings.json,编辑对应运行配置的applicationUrl项,将localhost替换为你的本地IP,同时保留对应端口:

    "profiles": {
      "IIS Express": {
        "commandName": "IISExpress",
        "launchBrowser": true,
        "environmentVariables": {
          "ASPNETCORE_ENVIRONMENT": "Development"
        },
        "applicationUrl": "http://192.168.XXXX:64645;https://192.168.XXXX:44314",
        "sslPort": 44314
      }
    }
    

    保存后,IDE会基于此配置生成applicationhost.config,不会再覆盖你的IP绑定。

  • 配置JetBrains IDE的运行调试项

    1. 点击IDE右上角运行按钮旁的下拉菜单,选择Edit Configurations
    2. 找到对应的ASP.NET运行配置,在Startup Settings(或Configuration标签页)中,设置Application URL为http://192.168.XXXX:64645和https://192.168.XXXX:44314
    3. 确认配置中的端口与launchSettings.json一致,取消IDE自动生成localhost绑定的选项(若有)
  • 处理HTTPS证书绑定
    使用本地IP访问HTTPS时,默认localhost证书无效,需将证书绑定到IP端口:

    1. 打开证书管理器(Win+R输入certmgr.msc),找到IIS Express的自签名证书,复制其证书指纹(去掉空格)
    2. 以管理员身份打开PowerShell,执行命令:
      netsh http add sslcert ipport=192.168.XXXX:44314 certhash=证书指纹 appid={项目GUID}
      
      项目GUID可在launchSettings.json的iisSettings.iisExpress.applicationId中找到
  • 开放防火墙端口
    打开Windows Defender防火墙,添加入站规则,允许TCP协议的64645和44314端口,确保手机能通过局域网访问该IP和端口

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.21 23:33:14