简体   繁体   English

ASP.NET 内核:生产连接串的放置位置

[英]ASP.NET Core: Where to place Connection String for Production

ASP.Net Core, using version 5.0.100, and I am trying to publish my web application to a hosting provider. ASP.Net Core,使用版本 5.0.100,我正在尝试将我的 web 应用程序发布到托管服务提供商。 I am trying to figure out where to place my connection string.我试图找出放置连接字符串的位置。 As of right now I have it inside appsetting.json .截至目前,我将它放在appsetting.json中。

"ConnectionString": {
    "default": "data source=.; database= myDataBase; user id =    sa; password = myPassw0rd",
  } 

Is this bad practice?这是不好的做法吗? I am worried that someone may find the connection string and hack the website.我担心有人可能会找到连接字符串并破解网站。 Thank you in advance!先感谢您!

There are several places you can put your connection string:有几个地方可以放置连接字符串:

  • Settings files, such as appsettings.json设置文件,如 appsettings.json
  • Environment variables环境变量
  • Azure Key Vault Azure 密钥库
  • Azure App Configuration Azure 应用程序配置
  • Command-line arguments命令行 arguments
  • Custom providers, installed or created自定义提供程序,安装或创建
  • Directory files目录文件
  • In-memory .NET objects内存中 .NET 对象

See the documentation for Configuration in ASP.NET Core for configuration for all of the above.有关上述所有配置,请参阅ASP.NET 内核中的配置文档。 Each option carries different kinds of risk, so you'll need to evaluate which one makes the most sense for your use case.每个选项都有不同类型的风险,因此您需要评估哪个选项对您的用例最有意义。

It's good that you're questioning how to best manage connection strings.很高兴您质疑如何最好地管理连接字符串。 Storing credentials in any configuration file like appsettings.json and web.config is a bad idea.在 appsettings.json 和 web.config 等任何配置文件中存储凭据是个坏主意。 There are a number of ways to protect your secrets.有多种方法可以保护您的秘密。 It really comes down to your specific use case.这实际上取决于您的特定用例。 My preferred method is using Application Pool Identities.我首选的方法是使用应用程序池标识。 Here aa few resources to get you started.这里有一些资源可以帮助您入门。

Connection String Security C# 连接字符串安全 C#

Protecting Connection Information 保护连接信息

Application Pool Identities 应用程序池标识

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

相关问题 我应该在哪里存储我的 ASP.NET Core 应用程序生产环境的连接字符串? - Where should I store the connection string for the production environment of my ASP.NET Core app? asp.net核心mvc连接字符串 - asp.net core mvc connection string ASP.NET Core中的连接字符串DI - Connection String DI in ASP.NET Core ASP.NET Core MacOS连接字符串 - ASP.NET Core MacOS Connection string ASP.NET CORE:生产中的数据库连接问题(SQLite) - ASP.NET CORE: Database Connection Issue (SQLite) in Production 在ASP.NET WebAPI中添加处理SQL连接字符串的方法的适当位置在哪里 - Where is the proper place to add a method to handle SQL Connection String in ASP.NET WebAPI 如何在共享服务器上托管的 ASP.Net Core 3.1 应用程序中存储生产机密,如连接字符串 - How can I store production secrets like connection string in ASP.Net Core 3.1 application, hosted on a shared server 在 aws eb 上存储 asp.net core 2 的连接字符串 - Store connection string for asp.net core 2 on aws eb Asp.Net Core中的运行时更改连接字符串 - Runtime change connection string in Asp.Net Core 将连接字符串传递给 asp.net core 中的自定义 AuthorizeAttribute - Pass connection string to custom AuthorizeAttribute in asp.net core
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM