【问题标题】:How to add HTTP endpoint to ASP.NET Core 6 app?如何将 HTTP 端点添加到 ASP.NET Core 6 应用程序?
【发布时间】:2022-02-06 23:50:50
【问题描述】:

我创建了一个 ASP.NET Core 6 应用程序,并在项目创建期间检查了“为 HTTPS 配置”。出于测试目的,我现在需要一个普通的 HTTP 端点。如何添加这样的端点?

我的代码目前如下所示:

var builder = WebApplication.CreateBuilder(args);

var app = builder.Build();
app.MapGet("/", () => "Hello World! - use /graphql");

app.Run();

【问题讨论】:

  • 你能分享你的launchSettings.json吗?
  • @Serhii 请在下面查看我的答案 :-) 你的问题已经以某种方式解决了我的问题 :-)

标签: asp.net-core http https .net-6.0


【解决方案1】:

Serhii 和 Serge 将我指向 launchSettings.json(请注意,它位于 Properties 文件夹中!)。看起来是这样的:

{
  "iisSettings": {
    "windowsAuthentication": false,
    "anonymousAuthentication": true,
    "iisExpress": {
      "applicationUrl": "http://localhost:20380",
      "sslPort": 44329
    }
  },
  "profiles": {
    "TestProject": {
      "commandName": "Project",
      "dotnetRunMessages": true,
      "launchBrowser": true,
      "applicationUrl": "https://localhost:7090;http://localhost:5090",
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    },
    "IIS Express": {
      "commandName": "IISExpress",
      "launchBrowser": true,
      "environmentVariables": {
        "ASPNETCORE_ENVIRONMENT": "Development"
      }
    }
  }
}

注意这一行

 "applicationUrl": "https://localhost:7090;http://localhost:5090",

并注意第二个 URL 是纯 HTTP。我可以毫无问题地调用此 URL(通常使用 F5 启动项目,自动调用 HTTPS 链接,但可以手动切换到浏览器中的 HTTP 链接)。

所以,我无事可做,不需要更改配置等 :-)

【讨论】:

    猜你喜欢
    • 2022-01-20
    • 2020-05-30
    • 2018-10-27
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-05-23
    • 2020-04-25
    • 1970-01-01
    相关资源
    最近更新 更多