Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC
Open Closed

implementing Azure App Configuration #8410


User avatar
0
BobIngham created

dotnet core, .net framework 4.6.1, angular, Zero 6.8.0 I would like to move my connection strings to Azure's App Configuration service. I'm not that good down in the magic of how Zero works and I'm scratching my head on how to implement the nuget package Microsoft.Extensions.Configuration.AzureAppConfiguration. Firstly, all advice points to upgrading to .aspnet framework 4.7.1 - am I safe to do this with Zero?

Zero's startup.cs looks as follows:

        public static IWebHostBuilder CreateWebHostBuilder(string[] args)
        {
            return new WebHostBuilder()
                //.CaptureStartupErrors(true)
                //.UseSetting("detailedErrors", "true")
                .UseKestrel(opt => opt.AddServerHeader = false)
                .UseContentRoot(Directory.GetCurrentDirectory())
                .UseIISIntegration()
                .UseStartup<Startup>();
        }

Instructions for ASPNET Core 3 tell me to modify code as follows:

public static IHostBuilder CreateHostBuilder(string[] args) =>
    Host.CreateDefaultBuilder(args)
    .ConfigureWebHostDefaults(webBuilder =>
    webBuilder.ConfigureAppConfiguration((hostingContext, config) =>
    {
        var settings = config.Build();
        config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfig"]);
    })
    .UseStartup<Startup>());

Or this for .NET Core 2:

public static IWebHostBuilder CreateWebHostBuilder(string[] args) =>
    WebHost.CreateDefaultBuilder(args)
        .ConfigureAppConfiguration((hostingContext, config) =>
        {
            var settings = config.Build();
            config.AddAzureAppConfiguration(settings["ConnectionStrings:AppConfig"]);
        })
        .UseStartup<Startup>();

Instructions for .NET framework say I should be adding the following to my App.config file but I don't have an App.config file.

<configSections>
    <section name="configBuilders" type="System.Configuration.ConfigurationBuildersSection, System.Configuration, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a" restartOnExternalChanges="false" requirePermission="false" />
</configSections>

<configBuilders>
    <builders>
        <add name="MyConfigStore" mode="Greedy" connectionString="${ConnectionString}" type="Microsoft.Configuration.ConfigurationBuilders.AzureAppConfigurationBuilder, Microsoft.Configuration.ConfigurationBuilders.AzureAppConfiguration" />
        <add name="Environment" mode="Greedy" type="Microsoft.Configuration.ConfigurationBuilders.EnvironmentConfigBuilder, Microsoft.Configuration.ConfigurationBuilders.Environment" />
    </builders>
</configBuilders>

<appSettings configBuilders="Environment,MyConfigStore">
    <add key="AppName" value="Console App Demo" />
    <add key="ConnectionString" value ="Set via an environment variable - for example, dev, test, staging, or production connection string." />
</appSettings>

I'm a little confused and admit to not being the best at this level. Can anyone point me in the right direction for adding Azure App Configuration to Zero 6.8.0?


10 Answer(s)
  • User Avatar
    0
    musa.demir created

    Hello @bobingham

    Instructions for ASPNET Core 3 tell me to modify code as follows:

    Will you upgrade your project to core 3.0?

  • User Avatar
    0
    BobIngham created

    Hi @demirmusa,

    Not for the purposes of this exercise - are you mad!!!! I'm still on 6.8.0 .NET framework 4.6.1. Can I upgrade to 4.7.1. Once upgraded how do I implement the Microsoft.Extensions.Configuration.AzureAppConfiguration in Zero 6.8.0? The instructions above are for explanatory purposes only.

  • User Avatar
    0
    musa.demir created

    Alright.

    Instructions for .NET framework say I should be adding the following to my App.config file but I don't have an App.config file.

    You can use Web.config file.

  • User Avatar
    0
    BobIngham created

    Hi @demirmusa, let's go one step at a time. Can I upgrade my .NET framework to 4.7.1 without causing any breaking changes to .NET Zero? Are there any known issues?

    Once we've established this I'll ask how to put AppConfig service into Startup.cs.

  • User Avatar
    0
    BobIngham created

    Hi @demirmusa, We are considering handing over our Zero development to a third party. We are currently talking to three Zero partners much bigger than us who can deal with the demand. Alper is helping us with this task, everything is completely transparent. How do I get my connection strings and authorizations out of the config files so I can pass along source code without giving access to my prospective partner? It's more a business question than a coding question, maybe Ishmael or Alper can help you out. BTW - I really appreciate the work you have done on Zero recently, I'm on an earlier version (6.8.0) but your current stuff is brilliant.

  • User Avatar
    0
    musa.demir created

    Hi @bobingham

    How do I get my connection strings and authorizations out of the config files so I can pass along source code without giving access to my prospective partner?

    Since your project is .net framework (not .net core), These may help you: https://docs.microsoft.com/en-us/previous-versions/aspnet/dtkwfdky%28v=vs.100%29?redirectedfrom=MSDN https://www.hanselman.com/blog/BestPracticesForPrivateConfigDataAndConnectionStringsInConfigurationInASPNETAndAzure.aspx

  • User Avatar
    0
    BobIngham created

    Hi @demirmusa, Thanks for the link. I will test that out using one of my deployment slots.

    Can I upgrade my .NET framework to 4.7.1 without causing any breaking changes to .NET Zero? Are there any known issues?

  • User Avatar
    0
    musa.demir created

    Not sure. You can check microsoft migration guides. https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/runtime/4.6-4.7.1 https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/retargeting/4.6-4.7.1

  • User Avatar
    1
    BobIngham created

    @demirmusa, brilliant, exactly what I was looking for. It also looks like it may get rid of the CultureUI warnings in the log files. As an aside, why isn't Zero on 4.7 as a matter of course?

  • User Avatar
    0
    ismcagdas created
    Support Team

    @bobingham please reopen if you still have issues with this. We can continue targeting .NET Framework 4.7 (or above) in 8.4 milestone discussion on GitHub.