简体   繁体   English

以编程方式访问存储帐户

[英]Accessing Storage account programmatically

In my c# solution I am accessing my storage account through a connection string.在我的 c# 解决方案中,我通过连接字符串访问我的存储帐户。

Issue -问题 -

  1. right now the cloud solution is in dev现在云解决方案正在开发中
  2. when the solution will be promoted to qa\prod - that string will change.当解决方案将被提升为 qa\prod - 该字符串将改变。 Is there an alternative better way to manage this ie to avoid code change throughout this promotion\env changes.是否有其他更好的方法来管理此问题,即避免在此promotion\env 更改期间更改代码。

one way i was thinking was use of vault.. any other idea?我想的一种方法是使用保险库..还有其他想法吗? Please guide.请指导。 Thanks.谢谢。

I assume you are talking about a Web App where you are using Storage Account Connection string.我假设您正在谈论 Web 应用程序,您在其中使用存储帐户连接字符串。

Usually, it's a good practice to have your connection string in a config file (web.config for.Net Framework and appsettings.json for .net core).通常,最好将连接字符串放在配置文件中(web.config 用于.Net Framework,appsettings.json 用于 .net 核心)。

However, though these work in Azure App Service, they are kind of deprecated.然而,虽然这些在 Azure 应用服务中工作,但它们有点被弃用。 So, you need to create App Settings / Connection Strings (go to Configuration blade in App Service) for your Storage Connection.因此,您需要为您的存储连接创建应用设置/连接字符串(转到应用服务中的配置刀片)。

You didn't mention what kind of application you have in your solution.你没有提到你的解决方案中有什么样的应用程序。 Based on the type you can use the below appropriate technique to access the App Settings/ connection strings.根据类型,您可以使用以下适当的技术来访问应用程序设置/连接字符串。

  1. .Net Framework - ConfigurationManager namespace .Net Framework - ConfigurationManager 命名空间
  2. .Net Core - IConfiguration .Net 核心 - IConfiguration

Thanks, Praveen谢谢, 普拉文

There are at least two things you should do.你至少应该做两件事。

  1. Use the Options pattern in ASP.NET Core to retrieve your settings like connections strings.使用ASP.NET 内核中的选项模式来检索您的设置,例如连接字符串。 This will, for example, use your appsettings.json if you work locally and it will overwrite these settings with environment variables you are setting in Azure.例如,如果您在本地工作,这将使用您的 appsettings.json,它将使用您在 Azure 中设置的环境变量覆盖这些设置。 This mean, you don't have to worry where your settings come from.这意味着,您不必担心您的设置来自哪里。

  2. Configure connection strings in your App Service application.在应用服务应用程序中配置连接字符串

Also consider using Key Vault references for App Service settings还可以考虑将 Key Vault 引用用于应用服务设置

I see you are using Azure DevOps.我看到您正在使用 Azure DevOps。

The old "config transforms" of yesteryear are arguably deprecated now with continuous deployment (CD).可以说,过去的旧“配置转换”现在已经被持续部署 (CD) 弃用了。 Essentially your connection string represents a "secret" or at least something that is stage-dependent and generally stage dependant items should not be part of the source code's repository.本质上,您的连接字符串表示“秘密”或至少是与阶段相关的东西,并且通常与阶段相关的项目不应成为源代码存储库的一部分。 Sure you can put them in but its much easier to manage in CD.当然你可以把它们放进去,但它更容易在 CD 中管理。

Instead, whoever is defining the CD pipeline defines it in other means such as DevOps CD variables and injects it into your config after the code has been compiled but just prior to deployment相反,定义 CD 管道的人会以其他方式定义它,例如 DevOps CD变量,并在编译代码之后但在部署之前将其注入到您的配置中

More更多的

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM