0

I have json object which is reading like configuration.Getsection("XYZconfig").Get(); in code it is working fine in local. After inserting the config values in azure keyvault the XYZconfig section is taking as below, The quotation is appending before and after brackets. so it is unable to read using configuration.Getsection("XYZconfig").Get(). How to read this config values.

"XYZconfig": "{ "key1":"vaule1", "key2":"value2", "key3":"value3" }"

2
  • you can use Trim like var configSection = configuration.GetSection("XYZconfig").Value.Trim('"'); Commented Dec 27, 2022 at 13:08
  • Hi @Jajula Siva, have you tried using Newtonsoft.Json to handle escaped strings which like mjb said: var XYZconfig = _configuration.GetSection("XYZconfig").Value; var key1 = JObject.Parse(XYZconfig).GetValue("key1");? Commented Jan 3, 2023 at 9:44

2 Answers 2

0

escape the string sequence

"XYZconfig": "{ \"key1\":\"vaule1\", \"key2\":\"value2\", \"key3\":\"value3\" }"

List of other string sequence:

https://www.freeformatter.com/json-escape.html

Sign up to request clarification or add additional context in comments.

1 Comment

still it is not working. after formatting the json like above
0

To access the configuration values you stored in Azure KeyVault from your ASP.NET Core web app, you can refer to following code snippet:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
    .ConfigureAppConfiguration((context, config) =>
    {

        var root = config.Build();
        config.AddAzureKeyVault($"https://{your_keyvault_name_here}.vault.azure.net/", $"{clientid_here}", $"{client_secret_here}");
    })
    .ConfigureWebHostDefaults(webBuilder =>
    {
        webBuilder.UseStartup<Startup>();
    });

Read configuration value:

private readonly ILogger<HomeController> _logger;
private readonly IConfiguration _config;

public HomeController(ILogger<HomeController> logger, IConfiguration config)
{
    _logger = logger;
    _config = config;
}

public async Task<IActionResult> Index()
{
    var val = _config["XYZconfig"];

enter image description here

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.