我遇到了一个问题,试图将我的Web服务部署到Azure虚拟机。它适用于任何其他环境,但当我将它部署到Azure时,它会崩溃。
服务设置如下所示:
IHostingEnvironment HostingEnvironment = null;
IConfiguration Configuration = null;
var builder = new WebHostBuilder()
.UseKestrel(options =>
{
options.Limits.MaxConcurrentConnections = null;
options.Limits.MaxRequestBodySize = WebSocketChannel.MaxMessageSize;
if (useSSL)
{
options.Listen(ipAddress, port, listenOptions =>
{
listenOptions.UseHttps(StoreName.My, domain, false, StoreLocation.LocalMachine);
});
options.ConfigureHttpsDefaults(adapterOptions =>
{
adapterOptions.SslProtocols = SslProtocols.Tls12;
});
}
else
{
options.Listen(ipAddress, port);
}
})
.UseContentRoot(Directory.GetCurrentDirectory())
.UseIISIntegration()
.ConfigureAppConfiguration((hostingContext, config) =>
{
HostingEnvironment = hostingContext.HostingEnvironment;
Configuration = config.Build();
})
.Configure(app =>
{
app.UseWebSockets(new WebSocketOptions()
{
KeepAliveInterval = TimeSpan.FromSeconds(60),
ReceiveBufferSize = WebSocketChannel.MaxMessageSize
});
app.Use(async (context, next) =>
{
switch (context.Request.Path)
{
case "/ws":
if (context.WebSockets.IsWebSocketRequest)
{
var connectionInfo = context.Connection;
var endPoint = new IPEndPoint(connectionInfo.RemoteIpAddress, connectionInfo.RemotePort);
await server.OnConnected(new WebSocketChannel(await context.WebSockets.AcceptWebSocketAsync()), endPoint);
}
else
{
context.Response.StatusCode = 400;
}
break;
case "/healthprobe":
{
var connectonInfo = context.Connection;
Logger.Log($"Healthprobe request from {connectonInfo.RemoteIpAddress}:{connectonInfo.RemotePort}");
context.Response.StatusCode = 200;
}
break;
default:
await next();
break;
}
});
});
当我设置useSSL=false时,它对Azure很好,但是如果我尝试使用证书,它就不接受连接。证书是100%正确的,由受信任的授权机构签名并安装到本地计算机证书存储中。
此外,我把这个证书到Azure证书库,但没有效果。
有什么办法让它起作用吗?
发布于 2018-07-27 13:14:38
我发现了问题所在。
实际上,这是一个证书验证过程。我试图使用其IP地址连接到服务器,但如果证书主题是域名,则无法通过验证。
https://stackoverflow.com/questions/-100005846
复制相似问题