【发布时间】:2019-01-20 06:36:26
【问题描述】:
我写了一个小的 ASP.NET Core 2 应用程序。它作为服务运行,因此没有 IIS。它在装有 Windows 7 SP1 的 PC 上运行。
var host = WebHost.CreateDefaultBuilder(args)
.UseContentRoot(pathToContentRoot)
.UseHttpSys(options =>
{
options.Authentication.Schemes = AuthenticationSchemes.None;
options.Authentication.AllowAnonymous = true;
options.MaxConnections = null;
options.MaxRequestBodySize = 30000000;
options.UrlPrefixes.Add("http://*:5050");
})
.UseStartup<Startup>()
.UseApplicationInsights()
.Build();
if (isService)
{
host.RunAsService();
}
else
{
host.Run();
}
如您所见,我想在端口 5050 上监听。没有 SSL 也可以正常工作。
我的问题是,如何为我的应用程序启用 https?再次:没有 IIS,没有域名(没有互联网连接)。通信只是在内部网络内部,所以我想使用自签名证书。
我阅读了文档 (HTTP.sys documentation;Netsh Commands;New-SelfSignedCertificate),但我的情况总是有所不同(他们使用 Krestel,或者是使用 IIS)。另外,我不知道如何为我的应用程序获取 App-ID(netsh 需要)。我试过这个:StackOverflow Get GUID 但它不起作用。
var assembly = typeof(Program).Assembly;
// following line produces: System.IndexOutOfRangeException
var attribute = (GuidAttribute)assembly.GetCustomAttributes(typeof(GuidAttribute), true)[0];
var id = attribute.Value;
Console.WriteLine(id);
所以我对所有的可能性和不同的配置有点困惑。而且文档没有考虑我的具体情况。
我创建了一个证书,我想我需要将它存储在“我的”商店中。 (那在哪里?cert:\LocalMachine\My)然后我需要为其分配我的 Applicaion ID 和端口。
但我不知道该怎么做。有人可以帮忙吗?
【问题讨论】:
标签: asp.net windows https ssl-certificate asp.net-core-2.0