自动部署后如何更改 appsettings.json 中的设置?

How can I change a setting in appsettings.json after auto-deploy?(自动部署后如何更改 appsettings.json 中的设置?)
本文介绍了自动部署后如何更改 appsettings.json 中的设置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个 ASP.NET Core 应用程序正在运行,并在其上设置了 Github 自动部署.但由于它是一个开放的 repo,我显然不想上传正确的配置文件.

我想做的是在 github 自动部署后替换 appsettings.json 中的一些字符串.

"AppSettings": {令牌":我的超级骗子秘密令牌"}

在 Azure 上部署 github 后,如何将 my super duper secret token 更改为我的真实令牌?

解决方案

据我所知,我们可以在 Azure 端口的应用设置中配置令牌.我对此进行了测试,它成功了,以下是我的详细步骤.

  1. 创建一个 Asp.net 核心应用程序.
  2. 在 appsetting.json 文件中添加 [AppSettings] 部分(令牌值:mysecretkey).
  3. 在创建的项目下添加一个公共类AppSettings.cs.
  4. 在Startup.cs文件的ConfigureService函数中添加代码services.Configure(Configuration.GetSection("AppSettings"))(对于.net Core 1.0).

<块引用>

注意:模型绑定的语法已从 RC1 更改为 RC2.使用 services.Configure<AppSettings>(Configuration.GetSection("AppSettings")) 不再可用为了将设置类绑定到您的配置,您需要在 Startup 的 ConfigureServices 方法中进行配置.CS:services.Configure<AppSettings>(options => Configuration.GetSection("AppSettings").Bind(options));

5. 将代码添加到 HomeController.cs 文件.

  1. 将 WebApp 发布到 Azure 门户.
  2. 在 Azure 门户中添加 [AppSettings: Token].
  3. 浏览 WebApp 并选择 about 选项卡以查看令牌值是门户中设置的值.

I have an ASP.NET Core application going on an have setup Github auto-deploy on it. But since it's an open repo I obviously don't want to upload my correct configuration file.

What I'd like to do is to replace some strings in the appsettings.json after a github auto deploy.

"AppSettings": {
    "Token": "my super duper secret token"
}

How can I change my super duper secret token to my real token after a github deploy on Azure?

解决方案

As I know we can config token in App Settings on the Azure port. I do a test on this, it works successfully, the following is my detail steps.

  1. Create an Asp.net core Application.
  2. Add [AppSettings] section in the appsetting.json file (Token vaule: mysecretkey).
  3. Add a public class AppSettings.cs under the created project.
  4. Add the code services.Configure<AppSettings>(Configuration.GetSection("AppSettings")) in the function ConfigureService function in the Startup.cs file (For .net Core 1.0).

Note:The syntax for model binding has changed from RC1 to RC2. Using services.Configure<AppSettings>(Configuration.GetSection("AppSettings")), is no longer availableIn order to bind a settings class to your configuration you need to configure this in the ConfigureServices method of Startup.cs: services.Configure<AppSettings>(options => Configuration.GetSection("AppSettings").Bind(options));

5. Add code to the HomeController.cs file.

  1. Publish the WebApp to the Azure Portal.
  2. Add [AppSettings: Token] in the Azure Portal.
  3. Browse the WebApp and select the about tab to see the token value is that the value set in the portal.

这篇关于自动部署后如何更改 appsettings.json 中的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!

本站部分内容来源互联网,如果有图片或者内容侵犯您的权益请联系我们删除!

相关文档推荐

c# Generic Setlt;Tgt; implementation to access objects by type(按类型访问对象的C#泛型集实现)
InvalidOperationException When using Context Injection in ASP.Net Core(在ASP.NET核心中使用上下文注入时发生InvalidOperationException)
how do i pass parameters to aspnet reportviewer(如何将参数传递给aspnet report查看器)
Bind multiple parameters from route and body to a model in ASP.NET Core(在ASP.NET Core中将路由和主体中的多个参数绑定到一个模型)
Custom model binding in AspNet Core WebApi?(AspNet Core WebApi中的自定义模型绑定?)
How to minify in .net core mvc view?(如何在.Net核心MVC视图中缩小?)