c# - 在 systemd 文件中使用 Environment= 解析 ASP.NET Core 连接字符串

标签 c# linux asp.net-core systemd

我一直在关注this guide 在 Ubuntu 18.04 服务器上设置我的 ASP.NET Core 应用程序。不过我遇到了一些麻烦。虽然当我设置 appsettings.json 连接字符串时它可以工作,但如果像这样放入 .service 文件中,它似乎无法读取输入的内容 Environment=ConnectionStrings:SqlServer="connectionString"

有什么巧妙的方法来处理这个问题吗?也许我错过了什么? 我用过systemd-escape "ConnectionStrings:SqlServer=\"<connectionString>\"确保它被正确转义,但应用程序似乎从未收到 connstr。

据说我将同时运行多个服务,并且它们不会使用相同的数据库。

最佳答案

想通了。

要解析 sqlserver 连接字符串,必须像这样添加:

Environment:SQLCONNSTR_<stringname>=<connstring>

除自定义类型外,还有其他三种类型。可以查看here

感谢所有花时间阅读本文的人!

关于c# - 在 systemd 文件中使用 Environment= 解析 ASP.NET Core 连接字符串,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/52834388/

相关文章:

c# - LINQ/lambda : How can I query a DB table based on information from another table?(多对多关系)

c - 在c程序中包含tk.h和tcl.h

c - setuid() 返回 0 但没有效果

linux - 这行代码在 shell 中是如何工作的?

c# - Entity Framework Core 预览版 2 - bool 值的默认值

c# - 在 IFrame 中的 ASP.NET Core 2.0 应用程序中使用 session 状态

c# - 如何解析日期后缀为 "th"、 "st"或 "nd"的日期?

c# - 应用程序级别变量

c# - asp.net core 2.0 授权在身份验证(JWT)之前触发

c# - 引用循环处理忽略不适用于 Asp.Net Core 3.0 Preview 3