【问题标题】:Running asp.net core Kestrel server on linux as a service在 linux 上作为服务运行 asp.net core Kestrel 服务器
【发布时间】:2020-03-09 18:23:12
【问题描述】:

我已经设置了一个 Ubuntu 18.04 Linux 服务器,并使用本地 Kestrel 和 Nginx 作为反向代理在其上运行我的 ASP.NET Core 2.1 应用程序。

当我使用dotnet run 运行应用程序时,它可以正常启动并且我可以访问该网站,但是如果我尝试根据this MS documentation 创建服务,服务器会正​​常启动(相同的 DLL、数据库、等),并且在尝试访问网页时似乎遇到了一些异常。

    ov 14 07:43:05:       Executed action method AcademiWeb.Controllers.HomeController.Index (AcademiWeb), returned result Microsoft.AspNetCore.Mvc.ViewResult in 0.4463ms.
Nov 14 07:43:05: #033[40m#033[32minfo#033[39m#033[22m#033[49m: Microsoft.AspNetCore.Mvc.ViewFeatures.ViewResultExecutor[1]
Nov 14 07:43:05:       Executing ViewResult, running view Index.
Nov 14 07:43:06: #033[40m#033[32minfo#033[39m#033[22m#033[49m: Microsoft.AspNetCore.Mvc.Internal.ControllerActionInvoker[2]
Nov 14 07:43:06 :       Executed action AcademiWeb.Controllers.HomeController.Index (AcademiWeb) in 151.9161ms
Nov 14 07:43:06: #033[41m#033[30mfail#033[39m#033[22m#033[49m: Microsoft.AspNetCore.Diagnostics.ExceptionHandlerMiddleware[1]
Nov 14 07:43:06 ]:       An unhandled exception has occurred while executing the request.
Nov 14 07:43:06 : System.ArgumentNullException: Value cannot be null.
Nov 14 07:43:06 : Parameter name: connectionString
Nov 14 07:43:06:    at Microsoft.EntityFrameworkCore.Utilities.Check.NotEmpty(String value, String parameterName)

这里有什么我可能遗漏的吗? appsettings 文件有什么问题吗?在线搜索没有得到任何相关结果。

【问题讨论】:

  • 有什么例外?请说清楚。 Kestrel 有它的日志记录,所以启用它并读取它的日志文件。
  • 我添加了异常,当它检查 connectionString 时它似乎为空 - 可能是访问 appsettings.json 的问题,但我不知道为什么会出现这个问题

标签: linux asp.net-core kestrel


【解决方案1】:

发现问题 - 我在服务中设置的工作目录是整个解决方案,而不是包含 appsettings.json 的正在运行的项目,所以当它是尝试访问其中的connectionString,值为null。

【讨论】:

    猜你喜欢
    • 2018-10-10
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多