相关疑难解决方法(0)

为 Asp.net core web api 启用 HTTPS 安全连接

我有使用 ASP.NET Core 2.1 创建的 REST API 应用程序。REST API 由 WebHostBuilder 创建并由 Kestrel 托管。

Startup.Kernel = kernel;
    _restApiServer = new WebHostBuilder()
      .UseKestrel(options =>
      {

      })
      .UseContentRoot(Directory.GetCurrentDirectory())
      .UseIISIntegration()
      .UseStartup<Startup>()
      .UseUrls(string.Format("http://localhost:{0}", _configuration.PortNumber))
      .UseSetting("https_port",_configuration.HttpsPort.ToString())
      .Build();
     _restApiServer.Run();
Run Code Online (Sandbox Code Playgroud)

默认情况下,REST API 在端口 8998 上提供服务。这个 REST API 是由我的不同应用程序启动的。我可以使用浏览器和 POSTMAN 连接到这个 REST API。

现在我想保护我与 REST API 的连接。我所做的是:我在 Configure 方法的 Startup 类中添加了必要配置以强制安全连接:

app.UseHttpsRedirection();
Run Code Online (Sandbox Code Playgroud)

而且我还执行了一个用于信任开发证书的代码:

dotnet dev-certs https --trust
Run Code Online (Sandbox Code Playgroud)

情况是,当我尝试通过浏览器访问 web api 时,出现错误:

本地主机拒绝连接。尝试:

检查连接

检查代理和防火墙

ERR_CONNECTION_REFUSED

此外,当我使用 POSTMAN 调用一些 REST API 方法时,我得到并出错:

无法得到任何回应

我究竟做错了什么?我需要在 Kestrel 配置中直接指定证书吗?

https asp.net-core-2.1

7
推荐指数
1
解决办法
1万
查看次数

Problems running/configure self hosted console application (ASP.net core 2.1, Kestrel) with public certificate on a windows webserver

I have developed various webservices in the past (VB ASP.net web-api applications) with https for production. I have done the development with http and then setup https on the production servers. To setup a port on the production server for https and the certificate, I have:

  1. Imported a public certificate in the certificate store on the windows server configured a specific port for https with netsh. E.g:

netsh http add urlacl url=https://+:22224/ user=everyone

  1. bound the certificate (over the thumbprint) …

https certificate asp.net-core-mvc kestrel-http-server asp.net-core-2.1

4
推荐指数
2
解决办法
1万
查看次数

无法在 Mac 上创建开发者证书

这发生在一夜之间。昨天我能够在我的 .NET Core we 应用程序上工作。现在,每次我尝试执行时dotnet run,我的 cmd 行都会出现以下错误:

在此处输入图片说明

如您所见,我尝试运行建议的命令来创建开发人员证书,dotnet dev-certs https然后dotnet dev-certs https --trust. 运行他们两个,我得到

将 HTTPS 开发人员证书保存到当前用户个人证书存储时出错。

在我运行这些命令之前,我在这个页面上读到我的钥匙串中有两个相互竞争的本地主机认证。所以我进入钥匙串删除其中一个无济于事。然后我删除了另一个认为我可以以某种方式重新创建它的想法。因此我运行上面的命令。

然后我发现对于命令dotnet dev-certs https [options]选项的大多数变体,我得到了相同的“保存 HTTPS 时出错...”错误(可以发现选项正在运行dotnet dev-certs https -h

任何人都知道为什么我可能会收到此错误?我怎样才能获得更多关于为什么它不能保存到“证书存储”的信息?似乎我被拒绝访问某种文件夹。

ssl certificate localhost keychain .net-core

4
推荐指数
2
解决办法
4780
查看次数