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

Visual Studio 2022中HotChocolate GraphQL应用报HTTP ERROR 502

问题:HotChocolate GraphQL应用运行时出现HTTP ERROR 502

我在Visual Studio 2022中基于.NET 6和.NET 7搭建简单默认GraphQL应用,使用HotChocolate.AspNetCore 13.5.1版本。运行应用时出现“localhost当前无法处理此请求。HTTP ERROR 502”错误。此前已开发过.NET 6的GraphQL应用,安装.NET 7后,无论是新建.NET 6或.NET 7的GraphQL应用,均无法加载并抛出该错误。应用访问URL为http://localhost:64264/graphql。曾尝试添加AddCors()和UseCors()配置解决,但未生效。

Query.cs文件

namespace GraphQL_Sample.Schema.Queries
{
    public class Query
    {
        public string Welcome()
        {
            return "Simple GraphQL App";
        }
    }
}

Program.cs文件

using GraphQL_Sample.Schema.Queries;

var builder = WebApplication.CreateBuilder(args);
{

    builder.Services.AddGraphQLServer()
        .AddQueryType<Query>();
}

var app = builder.Build();
{

    app.MapGraphQL();

    app.Run();
}

appsettings.json内容

{
  "Logging": {
    "LogLevel": {
      "Default": "Information",
      "Microsoft.AspNetCore": "Warning"
    }
  },
  "AllowedHosts": "*"
}

launchSettings.json内容

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:64264",
      "sslPort": 0
    }
  },
  "profiles": {
    "GraphQL_Sample": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "http://localhost:5208",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

错误页面显示:localhost当前无法处理此请求。HTTP ERROR 502

内容的提问来源于stack exchange,提问作者puneeth.c.s

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.07.08 15:36:20