代码拉取完成,页面将自动刷新
using System.Net;
using System.Net.Security;
using System.Security.Cryptography.X509Certificates;
using _10GrpcServer.Services;
using Microsoft.AspNetCore.Authentication.Certificate;
using Microsoft.AspNetCore.Server.Kestrel.Core;
using Microsoft.AspNetCore.Server.Kestrel.Https;
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddGrpc(x => { x.EnableDetailedErrors = true; });
builder.WebHost.ConfigureKestrel(o =>
{
o.ListenAnyIP(5000, listenOptions => { listenOptions.Protocols = HttpProtocols.Http2; });
// o.ListenAnyIP(5001, listenOptions =>
// {
// listenOptions.Protocols = HttpProtocols.Http2;
// listenOptions.UseHttps(X509CertificateLoader.LoadPkcs12FromFile("Certs/hardstyle.pfx", "pass1234"));
// });
o.ListenAnyIP(5005, listenOptions =>
{
listenOptions.UseHttps(httpsOptions =>
{
// var localhostCert = CertificateLoader.LoadFromStoreCert(
// "hardstyle", "My", StoreLocation.CurrentUser,
// allowInvalid: true);
var localhostCert = X509CertificateLoader.LoadPkcs12FromFile("Certs/hardstyle.pfx", "pass1234");
// var exampleCert = CertificateLoader.LoadFromStoreCert(
// "example.com", "My", StoreLocation.CurrentUser,
// allowInvalid: true);
listenOptions.UseHttps(new TlsHandshakeCallbackOptions
{
OnConnection = context =>
{
if (string.Equals(context.ClientHelloInfo.ServerName, "localhost",
StringComparison.OrdinalIgnoreCase))
{
// Different TLS requirements for this host
context.AllowDelayedClientCertificateNegotation = true;
return new ValueTask<SslServerAuthenticationOptions>(
new SslServerAuthenticationOptions
{
ServerCertificate = localhostCert
});
}
return new ValueTask<SslServerAuthenticationOptions>(
new SslServerAuthenticationOptions
{
ServerCertificate = localhostCert
});
}
});
});
});
});
var app = builder.Build();
app.MapGrpcService<GreeterService>();
app.MapGet("/", () => "Communication with gRPC endpoints must be made through a gRPC client. To learn how to create a client, visit: https://go.microsoft.com/fwlink/?linkid=2086909");
app.Run();
此处可能存在不合适展示的内容,页面不予展示。您可通过相关编辑功能自查并修改。
如您确认内容无涉及 不当用语 / 纯广告导流 / 暴力 / 低俗色情 / 侵权 / 盗版 / 虚假 / 无价值内容或违法国家有关法律法规的内容,可点击提交进行申诉,我们将尽快为您处理。