标签: kestrel-http-server

将 Kestrel 与命名管道一起使用?

我想知道是否有人知道如何让 Kestrel 监听命名管道,这样对使用 HTTPClient 的现有程序的唯一修改应该是将连接字符串从http://localhost更改为 net.pipe://localhost我能找到的最接近使用 Kestrel 和命名管道的是https://github.com/atlascode/Kestrel.Transport.Streams,但这对程序的修改比我想要完成的要更广泛。我还看到了一些关于带有命名管道的 libuv 的提示,但没有完全解释如何完成我正在寻找的东西。应用程序运行的目标环境是用于开发的 W10 和用于部署的 Azure。有人有什么想法吗?

提前致谢。

杰夫

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

5
推荐指数
0
解决办法
623
查看次数

为什么自定义 url 可以与 UseConfiguration 一起使用,而不可以与 ConfigureAppConfiguration 一起使用?

我一直在努力使用自定义urlsKestrel终于找到了有效的设置和构建器的组合,但我真的很困惑为什么以下工作会起作用:

var configuration =
    new ConfigurationBuilder()
        .AddJsonFile("hosting.json", optional: true, reloadOnChange: true)
        .Build();

var host =
    WebHost.CreateDefaultBuilder(args)
        .UseContentRoot(contentRootPath)
        .UseConfiguration(configuration)
        .UseStartup<Startup>()
        .Build();
Run Code Online (Sandbox Code Playgroud)

但不是这个:

var host =
    WebHost.CreateDefaultBuilder(args)
        .UseContentRoot(contentRootPath)
        .ConfigureAppConfiguration((context, builder) => 
        { 
            builder.AddJsonFile("hosting.json", optional: true, reloadOnChange: true); 
        })
        .UseStartup<Startup>()
        .Build();
Run Code Online (Sandbox Code Playgroud)

它只是忽略该hosting.json文件,就好像它不存在一样。


使用自己的构建器与使用扩展有什么区别ConfigureAppConfiguration?有什么时候使用哪个的经验法则吗?

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

5
推荐指数
0
解决办法
883
查看次数

使用 Kestrel 和 IIS 公开多个端口

我们正在 .NET Core 堆栈上构建服务。目前,我们在 IIS 反向代理后面使用 Kestrel 托管这些内容。

这些服务具有一些业务功能和一些管理/配置功能。我们正在考虑的一个想法是将它们暴露在不同的端口上。

现在是否可以使用 Kestrel 和 IIS 公开多个端口?使用 Docker 和 Kubernetes 应该可以实现这种场景,但我们还没有实现。

kestrel-http-server asp.net-core

5
推荐指数
0
解决办法
859
查看次数

Kestrel 修改传入的 http 标头

我有一个 IP 摄像机,我正在尝试从中接收事件。例如,如果它检测到帧的特定部分的运动,我想了解它并获取随事件捕获的图像。

问题是它使用 HTTP/1.0 POST 来发送此信息。根据规范(https://www.w3.org/Protocols/HTTP/1.0/draft-ietf-http-spec.html#BodyLength),正文长度可以通过 Content-Length 标头或通过关闭来传达所有内容都发送到服务器后的连接。IP 摄像机采用两种方法中的后者。

Kestrel 的 Web 服务器不支持此功能,如此处所示 Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.For() 包含以下内容(https://github.com/aspnet/KestrelHttpServer/blob/2191327b59f87f23f69fff2ac0dba9e58b67141b/ src/Kestrel.Core/Internal/Http/Http1MessageBody.cs,第 308-318 行):

// Avoid slowing down most common case
if (!object.ReferenceEquals(context.Method, HttpMethods.Get))
{
    // If we got here, request contains no Content-Length or Transfer-Encoding header.
    // Reject with 411 Length Required.
    if (context.Method == HttpMethod.Post || context.Method == HttpMethod.Put)
    {
        var requestRejectionReason = httpVersion == HttpVersion.Http11 ? RequestRejectionReason.LengthRequired : RequestRejectionReason.LengthRequiredHttp10;
        BadHttpRequestException.Throw(requestRejectionReason, context.Method);
    }
}
Run Code Online (Sandbox Code Playgroud)

结果,Kestrel 每次都会抛出 BadHttpRequestException。

关于如何解决这个问题有什么想法吗?

  • 可以在 …

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

5
推荐指数
0
解决办法
951
查看次数

如何修复下载时“失败 - 没有文件”?

我正在尝试设置适用于 Chrome 和 IE 10-11 的下载文件。它在大多数情况下适用于普通文件类型(EXE、PNG、TXT、..),但是当尝试下载没有文件类型的文本文件或像“000”这样的随机类型时,它会失败,显示“失败 - 否文件”。
有没有人知道可能导致这种情况的原因,或者如何解决?

我认为路径有问题,所以我导航到浏览器中同一目录中的另外几个文件。它们在没有 404 的情况下显示得很好,但是即使路径显然是正确的,尝试访问具有奇怪文件类型的文件也会返回 404。

我正在使用 Download.js;

$(document).on('click', '[download]', function (e) {
    e.preventDefault();
    download($(this).attr('href'));
});
Run Code Online (Sandbox Code Playgroud)

HTML;

<a href="~/edi_processed/@item.Name" class="download" download>@item.Name</a>
Run Code Online (Sandbox Code Playgroud)

变量“item”是“FileInfo”类的一个实例。

名为“Test.txt”的文件可以正常下载。
但名为“Test.000”的相同文本文件将显示“失败 - 无文件”。

javascript kestrel-http-server

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

Microsoft.AspNetCore.Connections.ConnectionResetException

一位客户不断收到此错误,我认为这是由于连接缓慢/延迟问题造成的,但想知道是否还有其他人遇到过此问题。

Microsoft.AspNetCore.Server.Kestrel|Connection id “0HLP5AO39QCJI”, Request id “0HLP5AO39QCJI:00000017”: An unhandled exception was thrown by the application. Microsoft.AspNetCore.Connections.ConnectionResetException: An existing connection was forcibly closed by the remote host ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host

at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.<GetResult>g__ThrowSocketException|7_0(SocketError e)
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketAwaitableEventArgs.GetResult()
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.ProcessReceives()
at Microsoft.AspNetCore.Server.Kestrel.Transport.Sockets.Internal.SocketConnection.DoReceive()
--- End of inner exception stack trace ---
at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
at System.IO.Pipelines.Pipe.GetReadAsyncResult()
at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.Http1MessageBody.PumpAsync()
at System.IO.Pipelines.PipeCompletion.ThrowLatchedException()
at System.IO.Pipelines.Pipe.GetReadResult(ReadResult& result)
at System.IO.Pipelines.Pipe.GetReadAsyncResult()
at System.IO.Pipelines.Pipe.DefaultPipeReader.GetResult(Int16 token)
at Microsoft.AspNetCore.Server.Kestrel.Core.Internal.Http.MessageBody.ReadAsync(Memory`1 buffer, …
Run Code Online (Sandbox Code Playgroud)

iis kestrel-http-server asp.net-core

5
推荐指数
0
解决办法
2302
查看次数

由 appsettings.json 标识的 Kestrel Https 证书仅在以管理员模式运行时发现

我正在使用 appsettings.json 在 .netcore3.1 应用程序中配置 Kestrel。这是 appsettings.json 中的相关部分

    "Kestrel": {
    "Certificates": {
      "Default": {
        "Subject": "certificate name",
        "Store": "MY",
        "Location": "LocalMachine",
        "AllowInvalid": true
      }
    }
  },
  "AllowedHosts": "*",
  "Urls": "http://*:5010;https://*:5011"
Run Code Online (Sandbox Code Playgroud)

如果我启动应用程序,它会出现在两个端口上。但是,通过 HTTPS 访问它会将此异常转储到我的应用程序的控制台

Microsoft.AspNetCore.Server.Kestrel[0] 处理 0HLT41KHBJ13T 时未处理的异常。System.ComponentModel.Win32Exception (0x8009030D): System.Net.SSPIWrapper.AcquireCredentialsHandle(SSPIInterface secModule, String package, CredentialUse intent, SCHANNEL_CRED scc) 无法识别提供给包的凭据

但是,如果我以管理权限启动应用程序,它就可以工作。因此,证书很好(它具有所需的私钥),但仍然无法正常工作。只是为了好玩,我将证书导入到 LocalUser 存储中,即使没有管理员权限,应用程序也绝对可以访问该存储,但没有任何乐趣。

如果没有以管理权限运行,有什么想法会导致此失败?您可以看到证书位于证书存储中,而不是文件系统中,这排除了文件权限问题。

https kestrel-http-server asp.net-core

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

如何通过 netcore3.1 中的环境变量更改 Kestrel (AspNetCore) 侦听端口

我有 aspnetcore3.1 项目,我想为 Kestrel 设置自定义端口(默认 5000 除外)。我可以Program.cs通过添加来做到这一点

Host.CreateDefaultBuilder(args)
.ConfigureWebHostDefaults(webBuilder =>
{
    webBuilder.ConfigureKestrel(options =>
    {
        options.ListenLocalhost(80);
    });
    webBuilder.UseStartup<Startup>();
})
Run Code Online (Sandbox Code Playgroud)

但这不能应用于我的情况,所以想知道,这如何通过环境变量来完成?

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

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

响应内容长度不匹配:写入的字节太少

我的 ASP.NET Core 应用程序使用“开箱即用”的外部登录身份验证。我想要实现的 - 在 facebook 挑战中,我想包装重定向 url 并将其作为 json 返回以在 jquery 前端使用。但请求结束后,我在浏览器中看到 500 错误,在应用程序控制台中看到下一个错误:

失败:Microsoft.AspNetCore.Server.Kestrel[13] 连接 ID“0HLV651D6KVJC”,请求 ID“0HLV651D6KVJC:00000005”:应用程序抛出了一个未处理的异常。System.InvalidOperationException:响应内容长度不匹配:写入的字节太少(470 个中的 0 个)。

我的外部登录操作,没什么特别看的

[HttpPost]
[AllowAnonymous]
[ValidateAntiForgeryToken]
public IActionResult ExternalLogin(string provider, string returnUrl = null)
{
    // Request a redirect to the external login provider.
    var redirectUrl = Url.Action(nameof(ExternalLoginCallback), "Account", new { returnUrl });
    var properties = _signInManager.ConfigureExternalAuthenticationProperties(provider, redirectUrl);
    return Challenge(properties, provider);
}
Run Code Online (Sandbox Code Playgroud)

脸书认证配置:

services.AddAuthentication().AddFacebook(facebookOptions =>
{
    facebookOptions.AppId = Configuration["Authentication:Facebook:AppId"];
    facebookOptions.AppSecret = Configuration["Authentication:Facebook:AppSecret"];

    facebookOptions.Events.OnRedirectToAuthorizationEndpoint =
        async (x) =>
        {

            UTF8Encoding …
Run Code Online (Sandbox Code Playgroud)

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

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

Asp.Net Core – Kestrel – 端口共享 – 替代方案

目前我们正在从 .Net Framework (4.7) 迁移到 .Net Core / Asp.Net Core。

我们有一些使用 WebAPI 并侦听同一端口 (443) 的微服务。

我们有一个单页应用程序(由几个模块(逻辑单元)组成),所有模块都使用相同的端口(443)与我们的微服务进行通信。

使用 Kestrel 时不支持 Asp.Net Core 端口共享,是否还有其他选择,然后使用反向代理,如 Nginx、Appache(“重定向”到不同端口)?

我们不能使用 IIS 作为反向代理,因为我们也在使用 IIS 目前不支持的 gRPC。

如果反向代理解决方案是正确的方法(我个人认为是,因为MS-doku,你能推荐一个反向代理,我们使用的是 Windows 并且需要对 spnego(Kerberos、NTLM v1、v2)的支持,至少代理应该能够将 spnego 转发到我们的 IIS,我们可能会将其用于其他应用程序和单点登录解决方案。

Nginx 看起来不错,但没有内置对 spnego 的支持(仅在付费/商业版本中)。

reverse-proxy tcpportsharing kestrel-http-server asp.net-core

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