我不記得我在哪看到這個,但是在爲我的.NET Core MVC應用程序設置我的應用程序配置時,我遵循了博客上的建議。我創造了這樣一個模型來保存一些設置我的應用程序需要:如何在.NET Core中進行應用程序設置以轉換爲Azure應用程序設置?
public class BasePathSettings
{
public string BaseImageFolder { get; set; }
public string BaseApiUrl { get; set; }
}
我的啓動有這個...
public void ConfigureServices(IServiceCollection services)
{
...
// this adds the base paths to container
services.Configure<BasePathSettings>(Configuration.GetSection("BasePathSettings"));
....
}
而且appsettings.json有這個在它:
"BasePathSettings": {
"BaseImageFolder": "D:\\Images\\",
"BaseApiUrl": "http://localhost:50321/"
},
我注入需要這種信息的控制器就像這樣...
private readonly BasePathSettings _settings;
public ClientsController(IOptions<BasePathSettings> settings)
{
_settings = settings.Value;
_client = new HttpClient();
_client.BaseAddress = new Uri(_settings.BaseApiUrl);
}
在我的本地主機上運行這一切運行良好。
但是,當我將此應用程序部署到Azure時,我認爲我需要在應用程序服務的常規設置中創建應用程序設置。所以我做了一個應用程序設置名爲BasePathSettings和複製的JSON的設置到值:
{ "BaseImageFolder": "imagePath", "BaseApiUrl": "apiUrl" }
看來,天青barfs當它在ConfigureServices代碼聲稱web.config中不具有正確的權限NTFS。我猜猜真正的罪魁禍首是如何從Azure應用程序設置中讀取json值。
我可以在那裏使用json嗎?如果是這樣,它需要格式不同嗎?