【问题标题】:IIS Express, ASP.NET Core - Invalid URI: The hostname could not be parsedIIS Express、ASP.NET Core - URI 无效:无法解析主机名
【发布时间】:2017-08-04 23:50:03
【问题描述】:

周末回来,去调试我的 Web 项目,它是一个 ASP.NET Core Web Api。它开始给我一个错误:无效的 URI:无法解析主机名。

我可以启动一个新的 asp.net core web api 项目,它调试得很好,所以我很确定它与我的这个项目的配置有关。有什么想法吗?

詹姆斯

【问题讨论】:

  • 我的问题是尝试按路径运行 dll。您必须将工作目录设置为发布目录(带有 dll 和所有支持文件),然后 dotnet .dll 并且它可以工作

标签: visual-studio iis-express asp.net-core-webapi


【解决方案1】:

我遇到了同样的问题,并在这篇文章中尝试了其他建议,但没有奏效。所以我去了项目的属性-> 调试-> WebServer 设置 在那里,我用 localhost 替换了 * ,这为我解决了这个问题。 Properties capture

【讨论】:

  • 这是一个正确的方法,因为它也处理 .net 核心项目(这些没有名为 .vs/config/applicationhost.config 的文件,而是 launchSettings.json - 至少我们的项目没有't)。
【解决方案2】:

解决方案:

  1. 关闭 Visual Studio
  2. 删除 .vs 文件夹

已修复:)

【讨论】:

  • 如果您有新问题,请点击 按钮提出问题。如果有助于提供上下文,请包含指向此问题的链接。 - From Review
  • @JigneshAnsodariya OP 遇到了同样的问题,并解释了他们是如何解决的。它回答了这个问题。
  • 工作 - 但之后可能需要重新选择解决方案的启动项目
【解决方案3】:

我遇到了类似的问题,在管理员模式下运行 Visual Studio 为我解决了这个问题。

【讨论】:

    【解决方案4】:

    Jakub 的回答确实解决了这个问题,因为它会导致 Visual Studio 重新生成 applicationhost.config。就我而言,错误是无法解析 <binding> 标记的值。我有以下内容: <binding protocol="http" bindingInformation="*:5000:*" /> 重新生成时看起来像这样: <binding protocol="http" bindingInformation="*:5000:localhost" /> 该文件位于“.vs”文件夹的“config”子文件夹中,无需删除整个目录,您只需将 <binding> 标记修复/恢复为可解析的值即可。

    编辑:根据@VeganHunter's comment* 不是有效的主机名。如果您希望它绑定到所有主机名,只需将主机留空即可。例如:*:80: 而不是 *:80:* 表示“所有网络接口/IP,端口 80,用于所有主机名”。

    【讨论】:

    • 这里有一个重要说明。当你有这行 IISExpress 只能作为 localhost 访问,不能通过 IP 地址从网络访问。为了使它通过IP地址工作,有些人建议像你提到的那样输入: 这实际上对我(和你)不起作用因为VS在重启后开始显示“无效的URI:无法解析主机名”错误。对我有用的是:
    • @VeganHunter 请将其发布为答案!这对很多人来说都非常有用,我相信会解决 OPs 的问题。
    【解决方案5】:

    我发布这个答案是因为很多人发现我的评论很有用。感谢@joshcomley 戳我。

    希望这个答案对某人有所帮助:

    1. 在您的解决方案文件夹中找到名为.vs 的子文件夹(注意,此文件夹具有隐藏属性,因此文件资源管理器默认不显示)
    2. 打开.vs/config/applicationhost.config文件
    3. 在文件中找到类似<site name="<Your_Web_Site_Name>" .... 的元素。你可以有几个这样的元素。您需要选择一个<Your_Web_Site_Name> 与您的网站名称相匹配的网站
    4. <site 元素内找到一个子元素,例如:

    <binding protocol="http" bindingInformation=":8080:localhost" />

    并将其替换为:

    <binding protocol="http" bindingInformation=":8080:" />

    1. 重建解决方案并运行网站

    注意事项:

    • 以端口号 8080 为例。您应该分配您实际用于网站的端口。
    • 此修复适用于 IISExpress 中托管的网站。它还可以避免像Invalid URI: The hostname could not be parsed 这样的错误消息。
    • 如果您的网站使用 IIS,您可以尝试使用以下行替换绑定: <binding protocol="http" bindingInformation="*:8080:*" />。并在此更改后执行iisreset

    【讨论】:

    • 我相信 bindingInformation="*:8080:*" 不会解析,但 ":8080:" 会解析,":8080:localhost" 也会解析
    • @QuickDanger,请在更改后尝试执行 iisreset。为我工作。
    • 对于任何寻找的人来说,这是"How do I allow IIS Express to accept remote connections?" 的答案,至少在 Windows 10 和 VS 2017 上。我不知道这是否改变了,但现在有很多错误信息推荐“ star" 语法,似乎 IIS Express 无法解析。谢谢@VeganHunter!
    【解决方案6】:

    此错误表明您的网站 bindingInformation 格式不正确。

    bindingInformation 的值由三部分组成。

    ip:port:host
    

    以下是一些绑定格式及其结果:

    <!-- Configures the site with a hostname of "www.test.com" on port 80 for the IP address of 192.168.1.10. -->
    <binding protocol="http" bindingInformation="192.168.1.10:80:www.test.com" />
    
    <!-- Configures the site with a hostname of "localhost" on port 80 for the IP address of 192.168.1.10. -->
    <binding protocol="http" bindingInformation="192.168.1.10:80:localhost" />
    
    <!-- Configures the site without a hostname and IP address on port 80. You'd use this setting to make your site directly accessible via any address that the system has, including the localhost address at 127.0.0.1, as well as any and all configured IP addresses. -->
    <binding protocol="http" bindingInformation=":80:" />
    
    <binding protocol="https" bindingInformation="*:443:" />
    <!-- Configures HTTPS bindings for all IP addresses over port 443. -->
    

    通过以上所有绑定,您可以将协议设置为 https 以使您的网站只能通过 SSL 访问。

    【讨论】:

      猜你喜欢
      • 2011-05-11
      • 2011-02-18
      • 2016-01-28
      • 2023-03-09
      • 1970-01-01
      • 2023-03-20
      • 1970-01-01
      • 2015-06-03
      • 1970-01-01
      相关资源
      最近更新 更多