【问题标题】:ASP.Net Core - Unexpected exception in IISHttpServer.HandleRequestASP.Net Core - IISHttpServer.HandleRequest 中的意外异常
【发布时间】:2020-01-12 05:41:06
【问题描述】:

我有ASP.Net Core 2.2 申请。从 Visual Studio 运行时运行良好(调试和发布模式)

但是当我在任何机器上将它部署到 IIS 时,它会抛出 500 错误。

"MessageTemplate": "出现意外异常 IISHttpServer.HandleRequest.", "Exception": "System.NullReferenceException: 对象引用未设置为对象的实例。\r\n at Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.GetOriginalPath()\r\n 在 Microsoft.AspNetCore.Server.IIS.Core.IISHttpContext.InitializeContext()\r\n 在 Microsoft.AspNetCore.Server.IIS.Core.IISHttpContextOfT`1.ProcessRequestAsync()\r\n 在 Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer.HandleRequest(IISHttpContext 语境)”, “特性”: { “SourceContext”:“Microsoft.AspNetCore.Server.IIS.Core.IISHttpServer” }

在谷歌上搜索,唯一的链接:

https://github.com/aspnet/AspNetCore/issues/6075

注意我在 IIS 中运行应用程序,StartMode 设置为 OnDemand

是什么导致了这个错误以及如何摆脱这个错误? 谢谢!

【问题讨论】:

标签: c# asp.net-core iis


【解决方案1】:

根据the link in your question,您可以考虑禁用预加载(作为修复基础错误之前的短期措施)。

即将 True 更改为 False

【讨论】:

    【解决方案2】:

    当应用程序在 IIS Express 或 IIS 中加载时,Swagger 文档运行正常。

    我怀疑这是否真的与 .Net Core 2.2IIS 兼容性有关。

    所以我创建了一个示例控制器,如下所示。

    public class SampleController : ControllerBase //.Net Core 2.2
    {
     [HttpGet]
     public async Task<IActionResult> Get()
     {
        return Ok("APIs up & running");
     }
     }
    

    从 Visual Studio 运行上述 API,然后在 IIS 上部署相同的 API,preload = true & then false

    毫不奇怪,API 运行没有问题。

    在实际的应用程序中,我使用AWS (Cognito) & 在最近的某个地方,我遇到了一些文章,其中提到 AWS 支持 .Net Core 2.1

    由于应用程序处于初始开发阶段,因此我们尝试检查相同的API.Net Core 2.1

    毫不奇怪,同样的 API 集运行没有问题。

    所以在我的情况下,它是 AWS Cognito(或其他服务)但不支持 .Net Core 2.2

    这个问题就是这样解决的。

    【讨论】:

      猜你喜欢
      • 2023-04-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-08-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多