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

ASP.NET WebForms项目IIS中修改项目URL调试遇阻求助

解决ASP.NET WebForms自定义域名调试问题

1. 修改IIS Express的applicationhost.config配置

找到项目对应的配置文件:

  • 项目级配置:{解决方案根目录}\.vs\{项目名称}\config\applicationhost.config(需显示隐藏文件夹)
  • 全局配置:C:\Users\{你的用户名}\Documents\IISExpress\config\applicationhost.config(不推荐,会影响所有IIS Express项目)

打开文件后,定位到你项目对应的<site>节点,修改<bindings>下的HTTPS绑定:

<site name="你的项目名" id="2">
    <application path="/" applicationPool="Clr4IntegratedAppPool">
        <virtualDirectory path="/" physicalPath="项目物理路径" />
    </application>
    <bindings>
        <!-- 替换原有localhost绑定为自定义域名 -->
        <binding protocol="https" bindingInformation="*:44302:prueba12.com" />
        <!-- 可选:保留HTTP绑定用于测试 -->
        <binding protocol="http" bindingInformation="*:8000:prueba12.com" />
    </bindings>
</site>

2. 配置HTTPS证书(关键步骤)

自定义域名的HTTPS需要对应证书,否则会触发浏览器安全拦截:

  1. 创建自签名证书:打开管理员权限的PowerShell,运行:
New-SelfSignedCertificate -DnsName "prueba12.com" -CertStoreLocation "cert:\LocalMachine\My"
  1. 复制证书哈希值:运行Get-ChildItem cert:\LocalMachine\My找到刚创建的证书,复制其Thumbprint值(去掉空格)。
  2. 绑定证书到端口:打开管理员权限的命令提示符,运行:
netsh http add sslcert ipport=0.0.0.0:44302 certhash=你的证书哈希值 appid={任意GUID,比如{12345678-1234-1234-1234-1234567890AB}}
  1. 信任证书:打开certlm.msc(证书管理器),找到目标证书,右键→所有任务→导出,再导入到受信任的根证书颁发机构→本地计算机存储中。

3. 调整项目属性设置

回到Visual Studio,右键项目→属性→Web:

  • 将项目URL设置为https://prueba12.com:44302/
  • 点击创建虚拟目录,此时不会再提示必须使用localhost
  • 确保勾选启用SSL

4. 启动调试验证

启动项目后,浏览器会自动打开https://prueba12.com:44302/,确认页面正常加载且无安全拦截提示。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.13 23:10:00