Sai*_*udo 4 azure application-settings azure-web-sites asp.net-core-mvc
我不记得我在哪里看到这个,但在为我的.NET Core MVC应用程序设置应用程序配置时,我在博客上遵循了建议.我创建了这样的模型来保存我的应用程序所需的一些设置:
public class BasePathSettings
{
public string BaseImageFolder { get; set; }
public string BaseApiUrl { get; set; }
}
Run Code Online (Sandbox Code Playgroud)
我的StartUp有这个......
public void ConfigureServices(IServiceCollection services)
{
...
// this adds the base paths to container
services.Configure<BasePathSettings>(Configuration.GetSection("BasePathSettings"));
....
}
Run Code Online (Sandbox Code Playgroud)
而appsettings.json中有这个:
"BasePathSettings": {
"BaseImageFolder": "D:\\Images\\",
"BaseApiUrl": "http://localhost:50321/"
},
Run Code Online (Sandbox Code Playgroud)
我注入了需要这些信息的控制器......
private readonly BasePathSettings _settings;
public ClientsController(IOptions<BasePathSettings> settings)
{
_settings = settings.Value;
_client = new HttpClient();
_client.BaseAddress = new Uri(_settings.BaseApiUrl);
}
Run Code Online (Sandbox Code Playgroud)
在我的localhost上运行它一切正常.
但是,当我将此应用程序部署到Azure时,我假设我需要在应用程序服务的常规设置中创建应用程序设置.所以我创建了一个名为BasePathSettings的应用程序设置,并将设置的json复制到值中:
{ "BaseImageFolder": "imagePath", "BaseApiUrl": "apiUrl" }
Run Code Online (Sandbox Code Playgroud)
似乎Azure barfs在ConfigureServices代码中声称web.config在NTFS中没有正确的权限.我猜测真正的罪魁祸首是如何从Azure应用程序设置中读取json值.
我甚至可以在那里使用json吗?如果是这样,它需要格式不同吗?
我甚至可以在那里使用json吗?如果是这样,它需要格式不同吗?
要向Azure Web应用程序添加层次结构设置,我们可以在节名称和键名之间放置一个冒号.例如,
use BasePathSettings:BaseImageFolder to set your folder
use BasePathSettings:BaseApiUrl to set your url
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1504 次 |
| 最近记录: |