标签: kestrel-http-server

交叉编译从Windows到Linux的dotnet核心应用程序

我在Windows工作,想在Windows上构建一个dotnet核心应用程序,以便在Linux上运行.在build文件夹中,我看到已发布文件夹中的.DLL文件引用,这显然不适用于Linux - 如何从我的Windows环境编译应用程序以在Linux上运行?可能吗?

在project.json文件中指定了运行时版本,我认为这与C:\ Program Files\dotnet\sdk\1.0.0-preview2-003121\runtimes位置中的运行时相关联?如果是这样,我如何在Windows中安装Linux运行时并引用它?

linux windows cross-compiling kestrel-http-server asp.net-core-1.0

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

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 mvc应用程序:

            Task hostingtask = Task.Factory.StartNew(() =>
            {
                Console.WriteLine("hosting ffoqsi");
                IWebHost host = new WebHostBuilder()
                    .UseKestrel()
                    .UseContentRoot(Directory.GetCurrentDirectory())
                    .UseIISIntegration()
                    .UseStartup<Startup>()
                    .UseApplicationInsights()
                    .Build();

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

当我取消此任务时,将抛出ObjectDisposedException.我怎样才能优雅地关闭主人?

asp.net-core-mvc kestrel-http-server asp.net-core

6
推荐指数
2
解决办法
3664
查看次数

如何从在 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
查看次数

Kestrel 和 OpenSSL 密码套件

如何从 Linux docker 容器中更改可用于 OpenSSL/Kestrel 的可用密码套件?

首先,让我们从一些环境细节开始:

  • 我们使用一个 Linux docker 容器(Docker 版本 17.06.0-ce,构建 02c1d87),我们通过 powershell 连接到它
  • 它托管一个用 C# 编写的 ASP.Net Core (netcore 1.1) Web 应用程序。
  • 主要针对 .NetStandard 1.4/1.6 编写,但计划迁移到 2.0。
  • 我们在 docker 容器上使用 Kestrel 作为我们的 Web 服务器
  • 据我所知,Kestrel 在后台使用 openSSL (1.0.1)。

我的 Program.cs 看起来像这样,它设置了 kestrel:

builder.UseKestrel(o => o.UseHttps(new HttpsConnectionFilterOptions
            {
                SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11,
                CheckCertificateRevocation = true,
                ClientCertificateMode = ClientCertificateMode.AllowCertificate 
                ServerCertificate = new X509Certificate2(certificate.Pfx, certificate.Password)
            }))
    .UseUrls(bindTo);
Run Code Online (Sandbox Code Playgroud)

关键是这样的:

SslProtocols = SslProtocols.Tls12 | SslProtocols.Tls11,
Run Code Online (Sandbox Code Playgroud)

无论我在这里设置什么值(Tls12、Tls11、Tls 或这些值的任何子集),它似乎都不会对连接可用的密码套件产生影响。我正在查看我的 URL 的 sslLabs 报告,由于旧协议上的 …

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

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

无法使用Angular 5客户端启动与信号器核心集线器的连接

我有一个运行SignalR核心集线器的.Net Core 2.0 C#Web Api.我甚至无法启动()我的hubConnection从angular(5.0.1)收到此错误:

选项https:// localhost:44301/hubs/sample 405(方法不允许)

错误:无法启动连接.错误:方法不允许

建立连接时出错:(

XHR加载失败:OPTIONS" https:// localhost:44301/hubs/sample ".

HttpError:XMLHttpRequest.xhr.onload不允许的方法[as __zone_symbol__ON_PROPERTYload](webpack-internal:///../../../../@aspnet/signalr-client/dist/src/HttpClient.js: 30:28)在ZoneDelegate.invokeTask(webpack-internal)的XMLHttpRequest.wrapFn(webpack-internal:///../../../../zone.js/dist/zone.js:1166:39) :///../../../../zone.js/dist/zone.js:425:31)在Object.onInvokeTask(webpack-internal:///../../ .. /core/esm5/core.js:4816:33)在ZoneDelegate.invokeTask(webpack-internal:///../../../../zone.js/dist/zone.js:424:36 )在Zone.runTask(webpack-internal:///../../../../zone.js/dist/zone.js:192:47)的ZoneTask.invokeTask [作为调用](webpack-)内部:///../../../../zone.js/dist/zone.js:499:34)在invokeTask(webpack-internal:///../../../) ../zone.js/dist/zone.js:1540:14)在XMLHttpRequest.globalZoneAwareCallback(webpack-internal:///../../../../zone.js/dist/zone.js :1566:17)

我正在努力甚至调试这个问题,即使在小提琴手的帮助下我也无法解决它.它似乎不是我的Api的问题,因为Kestrel控制台打印出来到集线器的请求进来,但不会打印任何错误.而且我可以毫无问题地获取,发送和发布到我的控制器.

这是我的StartUp.cs配置(我省略了与简洁无关的代码)

public void ConfigureServices(IServiceCollection services)
{
    services.AddCors(options =>
    {
        options.AddPolicy(
            "CorsPolicy",
            builder =>
                builder
                .AllowAnyOrigin()
                .AllowAnyHeader()
                .AllowAnyMethod()
                .AllowCredentials()
        );
    });

    services.AddAuthentication();
    services.AddMvcCore()
        .AddAuthorization(options => {...});
    services.AddAuthentication("Bearer")
        .AddIdentityServerAuthentication(options => {...});

    services.AddSignalR();
}

public void Configure(IApplicationBuilder app, IHostingEnvironment env)
{
    app.UseCors("CorsPolicy");
    app.UseAuthentication();

    app.UseSignalR(routes =>
    {
        routes.MapHub<SampleHub>("/hubs/sample");
    });

    app.UseMvc();
}
Run Code Online (Sandbox Code Playgroud)

这是我的示例中心

public interface ISampleHubClient 
{
    Task receiveMessage(SampleRequest …
Run Code Online (Sandbox Code Playgroud)

typescript kestrel-http-server asp.net-core-2.0 angular asp.net-core-signalr

6
推荐指数
2
解决办法
7254
查看次数

.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 在端口 80 上运行多个 ASP.NET Core(3.1x/最新)网站

我正在使用 (ASP).NET Core (3.1x)、C#、Blazor 和 Microsoft Kestrel Web 服务器,我想知道是否可以在一个 Kestrel 实例和端口 80 上运行 2 或 3 个不同的网站(域名) .我真的很想使用Kestrel作为唯一的Web服务器,而不是在它前面使用像nginx这样的代理服务器。

我已经在谷歌上搜索了一段时间的答案,但我找不到这个问题的答案。我正在租用托管服务器空间来运行 Ubuntu 18.04 VPS,我真的很想在这个 VPS 上运行多个网站,而不是租用多个 VPS。我正在考虑某种路由,但我无法弄清楚。

有没有办法使用 Kestrel 并在端口 80 上运行不同的网站?

更新 - 2020 年 2 月 25 日

我已经为此创建了一个Github 问题,长话短说:使用像 Nginx(适用于 Linux)这样的反向代理服务器。只有一个 Kestrel 进程可以在端口 80 上运行,并且没有一个好的方法可以用一个实例来托管多个网站。

更新 - 2021 年 5 月 4 日

现在可以使用 Microsoft 的反向代理“YARP”,它是一个单独的 Kestrel 实例。看我下面的回答。

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

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

使用Nginx反向代理时无法获取客户端的真实IP

问题描述:
当我访问应该返回我的远程客户端的 IP 地址的 Asp.net MVC Core 3.1 网页时,我反而获得了 Nginx 容器的内部 docker IP。我不确定问题是我在 asp.net core 中的代码,Nginx 反向代理配置没有将我的客户端 ip 转发到 Kestrel 容器,还是其他什么。

输出:

::ffff:172.23.0.3

所需的输出(使用随机 ip 的示例):

231.43.6.124

设置:

  • 使用 Ubuntu 和运行 Docker 的远程 VPS(即不在本地运行)
  • 没有公共访问权限的 Kestrel docker 容器
  • Nginx Docker 容器在端口 80 上具有公共访问权限并将请求转发到后端 kestrel 服务器。

配置文件

http {
        upstream backendservers {
                server kestrel:80;
        }
        server {
                listen 80;
                location / {
                        proxy_pass http://backendservers/;
                        proxy_set_header Host $host;
                        proxy_set_header X-Real-IP $remote_addr; 
                        proxy_set_header X-Forwarded-For $proxy_add_x_forwarded_for;
                        proxy_set_header X-Forwarded-Host $host:443;
                        proxy_set_header X-Forwarded-Server $host;
                        proxy_set_header X-Forwarded-Port …
Run Code Online (Sandbox Code Playgroud)

nginx docker asp.net-core-mvc kestrel-http-server asp.net-core

6
推荐指数
2
解决办法
7503
查看次数

使用 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
查看次数