Обновление ASP.NET Core appsettings.json в кодеC#

Место общения программистов C#
Ответить
Anonymous
 Обновление ASP.NET Core appsettings.json в коде

Сообщение Anonymous »


I am currently working on project using asp.net core v1.1, and in my appsettings.json I have:

"AppSettings": { "AzureConnectionKey": "***", "AzureContainerName": "**", "NumberOfTicks": 621355968000000000, "NumberOfMiliseconds": 10000, "SelectedPvInstalationIds": [ 13, 137, 126, 121, 68, 29 ], "MaxPvPower": 160, "MaxWindPower": 5745.35 }, I also have class that I use to store them:

public class AppSettings { public string AzureConnectionKey { get; set; } public string AzureContainerName { get; set; } public long NumberOfTicks { get; set; } public long NumberOfMiliseconds { get; set; } public int[] SelectedPvInstalationIds { get; set; } public decimal MaxPvPower { get; set; } public decimal MaxWindPower { get; set; } } And DI enabled to use then in Startup.cs:

services.Configure(Configuration.GetSection("AppSettings")); Is there any way to change and save MaxPvPower and MaxWindPower from Controller?

I tried using

private readonly AppSettings _settings; public HomeController(IOptions settings) { _settings = settings.Value; } [Authorize(Policy = "AdminPolicy")] public IActionResult UpdateSettings(decimal pv, decimal wind) { _settings.MaxPvPower = pv; _settings.MaxWindPower = wind; return Redirect("Settings"); } But it did nothing.


Источник: https://stackoverflow.com/questions/416 ... te-in-code
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «C#»