首页 > 解决方案 > 在 cors 主机中设置时是否需要在 C# 中定义协议

问题描述

我有一个关于 c# 的小问题。我是新手,实际上不是开发人员,但我需要知道一件事。在一个appsetting.json文件中,我有以下代码:

  },
  "Cors": {
    "AllowedOrigins": ["localhost:4000"]
  }

所以我的问题是我需要在这个地方定义协议并像这样写吗

  },
  "Cors": {
    "AllowedOrigins": ["http://localhost:4000"]
  }

当我尝试发送一些请求时,如果没有 http,服务器会以 204 No content code 响应。

标签: c#asp.net.netnode.js.net-core

解决方案


是的,您需要在来源中包含该方案。

这两个 URL 具有相同的来源:

  • https://example.com/foo.html
  • https://example.com/bar.html

以下 URL 的来源与前两个 URL 不同:

  • https://example.net– 不同的域

  • https://www.example.com/foo.html– 不同的子域

  • http://example.com/foo.html– 不同的方案

  • https://example.com:9000/foo.html– 不同的端口


推荐阅读