ASP.NET Core Controller脚手架:证书问题 [英] ASP.NET Core Controller scaffolding: certificate issue

本文介绍了ASP.NET Core Controller脚手架:证书问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这与大多数脚手架问题已解决,但我收到与证书有关的错误:

Most of scaffolding problem were resolved, but I'm getting error related to certificate:

在appsettings.json中,我有以下内容:

In appsettings.json I have the following:

"Kestrel": {
    "Endpoints": {
      "Localhost": {
        "Address": "127.0.0.1",
        "Port": "53688"
      },
      "LocalhostHttps": {
        "Address": "127.0.0.1",
        "Port": "44384",
        "Certificate": "HTTPS"
      }
    }
  },

和在appsettings.Development.json中:

and in appsettings.Development.json:

"Certificates": {
    "HTTPS": {
      "Source": "Store",
      "StoreLocation": "LocalMachine",
      "StoreName": "My",
      "Subject": "CN=localhost",
      "AllowInvalid": true
    },

环境就是发展:

为什么要问生产证书?

为什么我需要脚手架证书?

And why I need Certificate for scaffolding?

推荐答案

如果您在文档中稍加浏览,您会看到Kestrel不支持通过配置文件设置HTTPS终结点. Github的asp.net/security中还存在一个涉及此问题的问题.您可以按照此模式在Program.cs文件中进行设置....

If you dig around in the documentation a bit you'll see Kestrel does not support setting up an HTTPS endpoint via a configuration file. There is also a issue in Github asp.net/security that covers this in depth. You can set things up in the Program.cs file following this pattern....

public class Program
{
    public static void Main(string[] args)
    {
        BuildWebHost(args).Run();
    }

    public static IWebHost BuildWebHost(string[] args)
    {
        IHostingEnvironment env = null;

        return WebHost.CreateDefaultBuilder(args)
              .UseStartup<Startup>()
              .ConfigureAppConfiguration((hostingContext, config) =>
              {
                  env = hostingContext.HostingEnvironment;

                  config.AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
                          .AddJsonFile($"appsettings.{env.EnvironmentName}.json", optional: true, reloadOnChange: true);

                  if (env.IsDevelopment())
                  {
                      var appAssembly = Assembly.Load(new AssemblyName(env.ApplicationName));
                      if (appAssembly != null)
                      {
                          config.AddUserSecrets(appAssembly, optional: true);
                      }
                  }

                  config.AddEnvironmentVariables();

                  if (args != null)
                  {
                      config.AddCommandLine(args);
                  }
              })
              .UseKestrel(options =>
              {
                  if (env.IsDevelopment())
                  {
                      options.Listen(IPAddress.Loopback, 44321, listenOptions =>
                      {
                          listenOptions.UseHttps("testcert.pfx", "ordinary");
                      });
                  }
                  else
                  {
                      options.Listen(IPAddress.Loopback, 5000);
                  }
              })
              .Build();
    }
}

这篇关于ASP.NET Core Controller脚手架:证书问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆