【问题标题】:IISHttpServer OnDisconnect NullReferenceExceptionIISHttpServer OnDisconnect NullReferenceException
【发布时间】:2020-04-30 15:58:35
【问题描述】:

在运行主要基于执行端点的 .NET Core Web 应用程序时,在我的代码中调用 context.Response.Redirect(url, false) 之后,我经常在 AbortIO 调用中收到 NullReferenceException

有人有什么想法吗?

例如以下代码:

app.UseEndpoints(endpoints =>
{
    endpoints.MapGet("/someurl", async context => {
        context.Response.Redirect("/someotherurl", false);
    });
});

这里经常出错,因为context 为空:

private static void OnDisconnect(IntPtr pvManagedHttpContext)
{
    IISHttpContext context = null;
    try
    {
        context = (IISHttpContext)GCHandle.FromIntPtr(pvManagedHttpContext).Target;
        context.AbortIO(clientDisconnect: true);
    }
    catch (Exception ex)
    {
        context?.Server._logger.LogError(0, ex, $"Unexpected exception in {nameof(IISHttpServer)}.{nameof(OnDisconnect)}.");
    }
}

来源:Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer,第 173 行

【问题讨论】:

标签: c# asp.net-core asp.net-core-3.1 c#-8.0


【解决方案1】:

【讨论】:

    猜你喜欢
    • 2020-11-27
    • 1970-01-01
    • 1970-01-01
    • 2014-08-04
    • 2016-11-04
    • 2021-02-25
    • 2012-06-21
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多