[英]How can I set an ASP.Net Core exe.config value from Azure App Service Connection String
I have a ASP.Net Core 2.2 application, targeting .Net Framework 4.7.2 hosted on Azure App Services.我有一个 ASP.Net Core 2.2 应用程序,目标是托管在 Azure 应用服务上的 .Net Framework 4.7.2。 I want to use the Azure App Service Connection string to set my connection strings.
我想使用 Azure 应用服务连接字符串来设置我的连接字符串。 As I'm targeting .Net Framework, my app has a appname.exe.config file, in which the configuration elements are stored (entity framework being one of them).
由于我的目标是 .Net Framework,我的应用程序有一个 appname.exe.config 文件,其中存储了配置元素(实体框架就是其中之一)。
When I try to use the connection string, I get an error message "Format of the initialization string does not conform to specification starting at index 0.".当我尝试使用连接字符串时,收到错误消息“初始化字符串的格式不符合从索引 0 开始的规范。”。
I have tried these against a normal .Net Framework application and they work perfectly, but I assume because Asp.Net Core uses the out of process EXE file, the connection strings aren't being populated.我已经针对普通的 .Net Framework 应用程序尝试了这些,并且它们运行良好,但我认为因为 Asp.Net Core 使用进程外 EXE 文件,所以没有填充连接字符串。
Is there anything I can do about this?我能做些什么吗?
Thanks in advance, David提前致谢,大卫
From the above comment, you mentioned you are placing the connection string in a location.从上面的评论中,您提到将连接字符串放置在一个位置。 I am hoping you placed it in the constructor, Because the Connection String should be passed to your Constructor in Entity Framework 6, so it can read it easily when you are calling that constructor from your code.
我希望您将它放在构造函数中,因为连接字符串应该传递给实体框架 6 中的构造函数,因此当您从代码中调用该构造函数时,它可以轻松读取它。
You can refer to the below link to see how to handle the connection strings with ASP.NET Core Applications.您可以参考以下链接,了解如何使用 ASP.NET Core 应用程序处理连接字符串。
Handle Connection strings in EF6 处理 EF6 中的连接字符串
You can also refer to this below link on how you can set them in Appsettings.json.您还可以参考以下链接,了解如何在 Appsettings.json 中设置它们。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.