C# 源代码中的.net核心连接字符串

C# 源代码中的.net核心连接字符串,c#,.net-core,entity,C#,.net Core,Entity,我正在研究实体框架的.net核心示例 默认示例在数据库上下文的构造函数中包含以下内容 #warning To protect potentially sensitive information in your connection string, you should move it out of source code. See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection s

我正在研究实体框架的.net核心示例

默认示例在数据库上下文的构造函数中包含以下内容

#warning To protect potentially sensitive information in your connection string, you should move it out of source code. 
See http://go.microsoft.com/fwlink/?LinkId=723263 for guidance on storing connection strings.
optionsBuilder.UseSqlServer("Server=servername");
正如警告所说,链接中没有提到,我已经向微软提供了这个反馈


是否有存储sql连接字符串的首选方法?如果连接字符串位于appsettings.json中,则仍将在源代码管理中对其进行跟踪。包含appsettings.json中的未跟踪文件是最好的解决方案吗?

如果攻击者能够访问您的源代码信息,那么不管怎样,您都会受到攻击

编译后的.NET代码可以反编译,从而允许攻击者泄露敏感数据,如db用户密码


配置文件可以在发布前加密以隐藏敏感数据。请参见

您应该将它们存储在App.config或Web.config中,具体取决于您正在创建的应用程序的类型。您可以使用ConfigurationManager.config检索它们,而不将web.config保留在源代码管理中?不要共享任何包含数据库连接的文件。