简体   繁体   English

如何从 Azure 应用服务连接字符串设置 ASP.Net Core exe.config 值

[英]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 中设置它们。

ASP.Net Core App Settings ASP.Net 核心应用程序设置

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何从 .Net Frame Asp.Net 应用程序中的 Azure App Service 配置获取连接字符串? - How do I get a connection string from Azure App Service configuration in a .Net Frame Asp.Net application? Azure DB 连接字符串是 null 与 ASP.NET 核心应用程序 - Azure DB connection string is null with an ASP.NET Core app ConfigurationManager-如何从.exe.config中读取值 - ConfigurationManager - How to read a value from .exe.config 当托管在Azure应用程序服务中时,如何控制添加到ASP.NET核心Web应用程序中的HTTP响应标头? - How can I control the HTTP response headers added to my ASP.NET core web application when hosted in Azure app service? 如何在web.config之外的ASP.Net中保留连接字符串? - How can I persist a connection string in ASP.Net outside of web.config? ASP.NET Core应用到Azure应用服务上的Linux - ASP.NET Core app to Linux on Azure App Service 如何为 ASP.net/C# 应用程序配置文件值中的值添加与号 - How can I add an ampersand for a value in a ASP.net/C# app config file value 在 Azure 中为 ASP.NET Core Web 应用设置 SQL 连接字符串 - Setting the SQL connection string for ASP.NET Core web app in Azure 如何从ASP.Net Core中的SqlServerDBContextOptionsExtensions获取连接字符串 - How do I get the connection string from the SqlServerDBContextOptionsExtensions in ASP.Net Core ASP.NET Core 对 Azure 应用服务的 HTTP 请求缓慢 - ASP.NET Core slow HTTP requests to Azure App Service
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM