问题描述
我有一个 ASP.NET Core 应用程序正在运行,并在其上设置了 Github 自动部署.但由于它是一个开放的 repo,我显然不想上传正确的配置文件.
我想做的是在 github 自动部署后替换 appsettings.json 中的一些字符串.
"AppSettings": {令牌":我的超级骗子秘密令牌"}
在 Azure 上部署 github 后,如何将 my super duper secret token
更改为我的真实令牌?
据我所知,我们可以在 Azure 端口的应用设置中配置令牌.我对此进行了测试,它成功了,以下是我的详细步骤.
- 创建一个 Asp.net 核心应用程序.
- 在 appsetting.json 文件中添加 [AppSettings] 部分(令牌值:mysecretkey).
- 在创建的项目下添加一个公共类AppSettings.cs.
- 在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 文件.
- 将 WebApp 发布到 Azure 门户.
- 在 Azure 门户中添加 [AppSettings: Token].
- 浏览 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.
- Create an Asp.net core Application.
- Add [AppSettings] section in the appsetting.json file (Token vaule: mysecretkey).
- Add a public class AppSettings.cs under the created project.
- 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.
- Publish the WebApp to the Azure Portal.
- Add [AppSettings: Token] in the Azure Portal.
- Browse the WebApp and select the about tab to see the token value is that the value set in the portal.
这篇关于自动部署后如何更改 appsettings.json 中的设置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!