标签: kestrel-http-server

ECONNRESET 连接被对等 Kestrel 重置

我在 Azure 上的 Application Insight 中遇到此错误:

Microsoft.AspNet.Server.Kestrel.Networking.UvException:错误-4077 ECONNRESET 连接由对等方重置

我在 Github 上读到了这个错误(https://github.com/aspnet/KestrelHttpServer/issues/388)。

这究竟意味着什么?例如,如果用户在 AJAX 调用期间关闭浏览器,这可能会出现问题?我没有在我的平台上使用 Sockect。

我可以用任何方式修复它吗?我正在使用 ASP.NET Core RC1。

c# kestrel-http-server asp.net-core

6
推荐指数
1
解决办法
4005
查看次数

Kestrel 对于在 ALB 后面的 AWS ECS 上运行的 ASP.NET Core 网站是否足够?

我正准备将 ASP.NET Core MVC 网站部署到生产环境。该应用程序将部署到AWS ECS(EC2容器服务)。不建议使用 Kestrel 来处理来自互联网的流量,并且建议在前面放置一个反向代理。我的问题是,AWS ALB足够好吗?它执行 SSL 终止、负载平衡,并支持 HTTP/2 和 WebSocket。

我相信我正在放弃压缩(据我所知,ALB 或 Kestrel 都不支持它)。这个设置缺少什么?我应该考虑额外的反向代理(haproxy/nginx)吗?额外的复杂性已经足够了,如果没有必要的话,我不想走这条路。

asp.net amazon-web-services amazon-ecs kestrel-http-server asp.net-core

6
推荐指数
1
解决办法
2173
查看次数

如何从在 Kestrel asp.net core 上执行 ClientCertificateValidation 的函数中获取 HttpContext?

I have an asp.net core self hosted application within Kestrel. Part of the .UseKestrel options within my Program.cs Main() function is to use the ClientCertificateValidation() functionality to have my own function validate client certificates.

This validation functionality is working fine but my custom validation function needs to be able to add an identity role to the connection that has been validated. I know normally you could just use dependency injection to get HttpContext but since this is a function pointed …

kestrel-http-server asp.net-core

6
推荐指数
1
解决办法
511
查看次数

.NET Core 在处理 HTTPS 证书时出现未知错误

我正在尝试构建一个使用 HTTPS 连接的 .NET Core 服务器。

我使用工具创建了一个自签名证书dotnet dev-certs并设置了 Kestrel,如下所示:

    return WebHost.CreateDefaultBuilder(args)
                    .UseKestrel(options =>
                    {
                        options.Listen(IPAddress.Loopback, 5000, lisOpt => lisOpt.UseHttps("myCert.pfx", "test"));
                    })
                  .UseStartup<Startup>()
                .Build();
Run Code Online (Sandbox Code Playgroud)

但是当我尝试与我的客户端连接时,我不断收到此异常:

fail: Microsoft.AspNetCore.Server.Kestrel[0]
      Uncaught exception from the OnConnectionAsync method of an IConnectionAdapter.
System.Security.Authentication.AuthenticationException: Authentication failed, see inner exception. ---> System.ComponentModel.Win32Exception: An unknown error occurred while processing the certificate
   --- End of inner exception stack trace ---
   at System.Net.Security.SslState.StartSendAuthResetSignal(ProtocolToken message, AsyncProtocolRequest asyncRequest, ExceptionDispatchInfo exception)
   at System.Net.Security.SslState.CheckCompletionBeforeNextReceive(ProtocolToken message, AsyncProtocolRequest asyncRequest)
   at System.Net.Security.SslState.StartSendBlob(Byte[] incoming, Int32 count, AsyncProtocolRequest asyncRequest) …
Run Code Online (Sandbox Code Playgroud)

ssl ssl-certificate .net-core kestrel-http-server

6
推荐指数
1
解决办法
6701
查看次数

使用 Kestrel 时发生的 .NET 6 Web 应用程序崩溃

我有一个 .NET 6 Web 应用程序,在使用 Kestrel 时间歇性崩溃:

System.Net.Sockets.SocketException (995): The I/O operation has been aborted because of either a thread exit or an application request.
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.<GetResult>g__ThrowSocketException|5_0(SocketError e)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.GetResult(Int16 token)
   at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive()
   at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
   at System.IO.Pipelines.Pipe.GetReadAsyncResult()
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
   at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication`1 application)
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.<GetResult>g__ThrowSocketException|5_0(SocketError e)
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.GetResult(Int16 token)
         at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive()
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequests[TContext](IHttpApplication`1 application)
         at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol.ProcessRequestsAsync[TContext](IHttpApplication`1 application)
Microsoft.AspNetCore.Server.Kestrel: Warning: Connection processing ended abnormally.
Run Code Online (Sandbox Code Playgroud)

我无法可靠地导致它发生,但它最终总是会发生,通常是在跑步 5-20 分钟后。Web 应用程序完全停止运行,这是我们可以从任何日志记录中获取的最后一条消息。

这看起来像是某种套接字连接错误,但它发生在本地计算机上,并且在附加 VSCode 或 VS2022 调试器时发生。

整个堆栈都指向 Microsoft 代码,其中没有任何部分指向我们应用程序中的代码。

知道从哪里开始解决这个问题吗?可能是什么原因造成的?

asp.net kestrel-http-server .net-6.0

6
推荐指数
1
解决办法
892
查看次数

aspnet5 vNext(rc1)iis 8 - 糟糕的网关502.3

我意识到这样的帖子存在,我已阅读/重读,但仍然有问题.大多数都是旧的或没有直接相关的,所以我想我会重新发布一个当前的例子.

尝试在win server 2012 R2上运行IIS 8.5+中的基本站点.此时我被困在" 502.3 - Bad Gateway "(错误代码80070002,模块httpPlatformHandler,通知executeRequestHandler,处理程序httpplatformhandler)

相关信息:

  • dnx 1.0.0-rc1-final clr(x64)
  • IIS - 安装/验证HttpPlatformHandler 1.2已安装(v1.2.1959)
  • IIS - 设置"无管理代码"池/站点
  • 在服务器本身上,如果我直接从命令行运行"kestrel.cmd"(通过dnu发布生成)并导航到该站点,我可以显示该站点.
    • Project.json:
{
  "version": "1.0.0-*",
  "dependencies": {
    "Microsoft.AspNet.Server.Kestrel": "1.0.0-rc1-final",
    "Microsoft.AspNet.IISPlatformHandler": "1.0.0-rc1-final",
    "Microsoft.AspNet.StaticFiles": "1.0.0-rc1-final"
  },
  "commands": {
    "kestrel": "Microsoft.AspNet.Server.Kestrel"
  },
  "frameworks": {
    "dnx451": {}
  },
  "publishExclude": [
    "node_modules",
    "bower_components",
    "**.xproj",
    "**.user",
    "**.vspscc"
  ],
  "exclude": [
    "www",
    "node_modules",
    "bower_components"
  ],
  "scripts": {
    "prepublish": [
      "npm install",
      "bower install"
    ]
  }
}
Run Code Online (Sandbox Code Playgroud)
  • dnu发布后生成的Web.config:
<configuration>
  <system.webServer>
    <handlers>
      <add name="httpplatformhandler" path="*" verb="*" modules="httpPlatformHandler" …
Run Code Online (Sandbox Code Playgroud)

iis dnx kestrel-http-server asp.net-core

5
推荐指数
1
解决办法
2104
查看次数

无法从命令行更改Kestrel监听端口

我有以下入口点:

public static void Main(string[] args)
{
    var config = new ConfigurationBuilder()
        .SetBasePath(Directory.GetCurrentDirectory())
        .AddJsonFile("hosting.json", optional: true)
        .AddCommandLine(args)
        .AddEnvironmentVariables()
        .Build();

    var host = new WebHostBuilder()
        .UseConfiguration(config)
        .UseKestrel()
        .UseContentRoot(Directory.GetCurrentDirectory())
        .UseIISIntegration()
        .UseStartup<Startup>()
        .Build();

    host.Run();
}
Run Code Online (Sandbox Code Playgroud)

如果我添加hosting.json文件,例如

{
  "server.urls": "http://0.0.0.0:5001"
}
Run Code Online (Sandbox Code Playgroud)

或者如果我定义环境变量(在这里找到名称)

SET ASPNETCORE_URLS=https://0.0.0.0:5001
Run Code Online (Sandbox Code Playgroud)

但是,如果我--server.urls http://0.0.0.0:5001作为参数传递,则应用程序将监听默认的5000端口:

> dotnet run --server.urls http://0.0.0.0:5001
...
Now listening on: http://localhost:5000
Run Code Online (Sandbox Code Playgroud)

kestrel-http-server asp.net-core

5
推荐指数
1
解决办法
2840
查看次数

HttpClient从Kestrel + IIS调用缓慢

我在一个IIS反向代理后面的Kestrel中运行了一个简单的asp.net core 2.0 WebApi应用程序.单个路由非常简单,它只是发出一个http请求:

using (HttpClient client = new HttpClient())            
{
    client.BaseAddress = new Uri("http://www.google.ca");               
    HttpResponseMessage response = await client.GetAsync("/search?q=test&oq=test");

    return Ok();
}
Run Code Online (Sandbox Code Playgroud)

但是,此请求始终需要2-3秒才能完成.然而,如果我在没有IIS的情况下直接运行Kestrel,相同的代码需要大约100ms.

我按照所有Microsoft 文档来配置使用IIS的kestrel.

iis reverse-proxy dotnet-httpclient kestrel-http-server asp.net-core-2.0

5
推荐指数
1
解决办法
618
查看次数

通过IKeyVaultClient.GetCertificateAsync检索时,Azure Key Vault证书没有私钥

我有两种方法可以执行相同的操作,但是Azure已弃用了一种可行的方法,而另一种方法则无效。

可行但不建议使用的方法:

我将PFX存储在Azure Key Vault Secrets中。(当我创建密码时,我会看到一条警告,指出该功能已被弃用)

并使用以下代码对其进行检索以创建我的证书:

        SecretBundle secret = await keyVaultClient.GetSecretAsync(keyVaultUrl, "MyCert-Secret");
        X509Certificate2Collection exportedCertCollection = new X509Certificate2Collection();
        exportedCertCollection.Import(Convert.FromBase64String(secret.Value));
        X509Certificate2 certFromSecret = exportedCertCollection.Cast<X509Certificate2>().Single(s => s.HasPrivateKey);
Run Code Online (Sandbox Code Playgroud)

归功于这个答案

我可以使用此证书成功托管和访问我的应用程序。

该方法不起作用,但我应该使用:

我将证书存储在Azure密钥库证书中

并使用以下代码进行检索并创建X509Certificate2:

        CertificateBundle certificateBundle = await keyVaultClient.GetCertificateAsync(keyVaultUrl, "MyCert-Certificate");
        X509Certificate2 certFromCertificate = new X509Certificate2(certificateBundle.Cer);
Run Code Online (Sandbox Code Playgroud)

这种方法的问题在于证书不包含私钥。即certFromCertificate.HasPrivateKey为false。

我的问题

为什么certFromSecret没有私钥,而certFromCertificate没有私钥?

我如何从密钥库中检索证书,在其中可以创建X509Certificate2对象以使用UseHttps将应用程序托管在Kestrel中。

我是这个主题的新手,所以我将不胜感激。

ssl x509certificate2 tls1.2 azure-keyvault kestrel-http-server

5
推荐指数
2
解决办法
3898
查看次数

Kestrel在提供流量时抛出“无效的主机头”错误

我们最近已经将ASP.NET MVC 5应用程序迁移到ASP.NET Core 2.2。

一切似乎都正常,但是我们定期收到以下异常(大约每秒3次,稍后会更多):

BadHttpRequestException: Invalid Host header: '~^appname.*$'
  Module "Microsoft.AspNetCore.Server.Kestrel.Core.BadHttpRequestException", line 0, col 0, in Throw
    Void Throw(Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.RequestRejectionReason, System.String)
  Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection", line 95, col 0, in EnsureHostHeaderExists
    Void EnsureHostHeaderExists()
  Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1Connection", line 196, col 0, in TryParseRequest
    Boolean TryParseRequest(System.IO.Pipelines.ReadResult, Boolean ByRef)
  Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol+<ProcessRequests>d__185`1", line 170, col 0, in MoveNext
    Void MoveNext()
  Module "System.Runtime.ExceptionServices.ExceptionDispatchInfo", line 12, col 0, in Throw
    Void Throw()
  Module "System.Runtime.CompilerServices.TaskAwaiter", line 46, col 0, in HandleNonSuccessAndDebuggerNotification
    Void HandleNonSuccessAndDebuggerNotification(System.Threading.Tasks.Task)
  Module "Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.HttpProtocol+<ProcessRequestsAsync>d__184`1", line 135, col 0, …
Run Code Online (Sandbox Code Playgroud)

kestrel-http-server asp.net-core

5
推荐指数
1
解决办法
378
查看次数