Reading settings from a Azure Function










11















I'm new to Azure's function... I've created a new timer function (will be fired every 30 minutes) and it has to perform a query on a url, then push data on the buffer..



I've done



public static void Run(TimerInfo myTimer, TraceWriter log)



var s = CloudConfigurationManager.GetSetting("url");

log.Info(s);




And in my function settings I've



enter image description here



What am I doing wrong?
Thanks










share|improve this question


























    11















    I'm new to Azure's function... I've created a new timer function (will be fired every 30 minutes) and it has to perform a query on a url, then push data on the buffer..



    I've done



    public static void Run(TimerInfo myTimer, TraceWriter log)



    var s = CloudConfigurationManager.GetSetting("url");

    log.Info(s);




    And in my function settings I've



    enter image description here



    What am I doing wrong?
    Thanks










    share|improve this question
























      11












      11








      11


      2






      I'm new to Azure's function... I've created a new timer function (will be fired every 30 minutes) and it has to perform a query on a url, then push data on the buffer..



      I've done



      public static void Run(TimerInfo myTimer, TraceWriter log)



      var s = CloudConfigurationManager.GetSetting("url");

      log.Info(s);




      And in my function settings I've



      enter image description here



      What am I doing wrong?
      Thanks










      share|improve this question














      I'm new to Azure's function... I've created a new timer function (will be fired every 30 minutes) and it has to perform a query on a url, then push data on the buffer..



      I've done



      public static void Run(TimerInfo myTimer, TraceWriter log)



      var s = CloudConfigurationManager.GetSetting("url");

      log.Info(s);




      And in my function settings I've



      enter image description here



      What am I doing wrong?
      Thanks







      azure






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Apr 22 '17 at 7:02









      advapiadvapi

      1,06911134




      1,06911134






















          3 Answers
          3






          active

          oldest

          votes


















          11














          You need to go to Platform Features -> Application settings and add it there.



          Application settings



          Settings



          Add the setting under App settings.




          Reading the setting can be done by first adding this at the top:



          using System.Configuration;


          And then reading a setting with:



          string setting = ConfigurationManager.AppSettings["url"];


          Where url is your setting key. The setting variable will contain your setting value.






          share|improve this answer

























          • Thanks for your reply... but how do i read them from script?

            – advapi
            Apr 22 '17 at 12:16






          • 1





            Check my update, System.Configuration.ConfigurationManager is the class I use typically.

            – juunas
            Apr 22 '17 at 12:18






          • 2





            Note that during development you will need to set these configuration values in local.settings.json.

            – Jaime Hablutzel
            Dec 15 '17 at 6:05


















          28














          Note that for Azure Functions v2 this is no longer true.
          The following is from Jon Gallant's blog:



          For Azure Functions v2, the ConfigurationManager is not supported and you must use the ASP.NET Core Configuration system:




          1. Include the following using statement:



            using Microsoft.Extensions.Configuration;



          2. Include the ExecutionContext as a parameter



            public static void Run(InboundMessage inboundMessage, 
            TraceWriter log,
            out string outboundMessage,
            ExecutionContext context)



          3. Get the IConfiguration Root



            var config = new ConfigurationBuilder()
            .SetBasePath(context.FunctionAppDirectory)
            .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
            .AddEnvironmentVariables()
            .Build();



          4. And use it to reference AppSettings keys



            var password = config["password"]


          When debugging locally, it gets the settings from local.settings.json under the "Values" keyword. When running in Azure, it gets the settings from the Application settings tab.






          share|improve this answer
































            6














            You can use System.Environment.GetEnvironmentVariable like this:



            var value = Environment.GetEnvironmentVariable("your_key_here")


            This gets settings whenever you're working locally or on Azure.






            share|improve this answer

























              Your Answer






              StackExchange.ifUsing("editor", function ()
              StackExchange.using("externalEditor", function ()
              StackExchange.using("snippets", function ()
              StackExchange.snippets.init();
              );
              );
              , "code-snippets");

              StackExchange.ready(function()
              var channelOptions =
              tags: "".split(" "),
              id: "1"
              ;
              initTagRenderer("".split(" "), "".split(" "), channelOptions);

              StackExchange.using("externalEditor", function()
              // Have to fire editor after snippets, if snippets enabled
              if (StackExchange.settings.snippets.snippetsEnabled)
              StackExchange.using("snippets", function()
              createEditor();
              );

              else
              createEditor();

              );

              function createEditor()
              StackExchange.prepareEditor(
              heartbeatType: 'answer',
              autoActivateHeartbeat: false,
              convertImagesToLinks: true,
              noModals: true,
              showLowRepImageUploadWarning: true,
              reputationToPostImages: 10,
              bindNavPrevention: true,
              postfix: "",
              imageUploader:
              brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
              contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
              allowUrls: true
              ,
              onDemand: true,
              discardSelector: ".discard-answer"
              ,immediatelyShowMarkdownHelp:true
              );



              );













              draft saved

              draft discarded


















              StackExchange.ready(
              function ()
              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43556311%2freading-settings-from-a-azure-function%23new-answer', 'question_page');

              );

              Post as a guest















              Required, but never shown

























              3 Answers
              3






              active

              oldest

              votes








              3 Answers
              3






              active

              oldest

              votes









              active

              oldest

              votes






              active

              oldest

              votes









              11














              You need to go to Platform Features -> Application settings and add it there.



              Application settings



              Settings



              Add the setting under App settings.




              Reading the setting can be done by first adding this at the top:



              using System.Configuration;


              And then reading a setting with:



              string setting = ConfigurationManager.AppSettings["url"];


              Where url is your setting key. The setting variable will contain your setting value.






              share|improve this answer

























              • Thanks for your reply... but how do i read them from script?

                – advapi
                Apr 22 '17 at 12:16






              • 1





                Check my update, System.Configuration.ConfigurationManager is the class I use typically.

                – juunas
                Apr 22 '17 at 12:18






              • 2





                Note that during development you will need to set these configuration values in local.settings.json.

                – Jaime Hablutzel
                Dec 15 '17 at 6:05















              11














              You need to go to Platform Features -> Application settings and add it there.



              Application settings



              Settings



              Add the setting under App settings.




              Reading the setting can be done by first adding this at the top:



              using System.Configuration;


              And then reading a setting with:



              string setting = ConfigurationManager.AppSettings["url"];


              Where url is your setting key. The setting variable will contain your setting value.






              share|improve this answer

























              • Thanks for your reply... but how do i read them from script?

                – advapi
                Apr 22 '17 at 12:16






              • 1





                Check my update, System.Configuration.ConfigurationManager is the class I use typically.

                – juunas
                Apr 22 '17 at 12:18






              • 2





                Note that during development you will need to set these configuration values in local.settings.json.

                – Jaime Hablutzel
                Dec 15 '17 at 6:05













              11












              11








              11







              You need to go to Platform Features -> Application settings and add it there.



              Application settings



              Settings



              Add the setting under App settings.




              Reading the setting can be done by first adding this at the top:



              using System.Configuration;


              And then reading a setting with:



              string setting = ConfigurationManager.AppSettings["url"];


              Where url is your setting key. The setting variable will contain your setting value.






              share|improve this answer















              You need to go to Platform Features -> Application settings and add it there.



              Application settings



              Settings



              Add the setting under App settings.




              Reading the setting can be done by first adding this at the top:



              using System.Configuration;


              And then reading a setting with:



              string setting = ConfigurationManager.AppSettings["url"];


              Where url is your setting key. The setting variable will contain your setting value.







              share|improve this answer














              share|improve this answer



              share|improve this answer








              edited Apr 22 '17 at 12:17

























              answered Apr 22 '17 at 11:03









              juunasjuunas

              23.5k35182




              23.5k35182












              • Thanks for your reply... but how do i read them from script?

                – advapi
                Apr 22 '17 at 12:16






              • 1





                Check my update, System.Configuration.ConfigurationManager is the class I use typically.

                – juunas
                Apr 22 '17 at 12:18






              • 2





                Note that during development you will need to set these configuration values in local.settings.json.

                – Jaime Hablutzel
                Dec 15 '17 at 6:05

















              • Thanks for your reply... but how do i read them from script?

                – advapi
                Apr 22 '17 at 12:16






              • 1





                Check my update, System.Configuration.ConfigurationManager is the class I use typically.

                – juunas
                Apr 22 '17 at 12:18






              • 2





                Note that during development you will need to set these configuration values in local.settings.json.

                – Jaime Hablutzel
                Dec 15 '17 at 6:05
















              Thanks for your reply... but how do i read them from script?

              – advapi
              Apr 22 '17 at 12:16





              Thanks for your reply... but how do i read them from script?

              – advapi
              Apr 22 '17 at 12:16




              1




              1





              Check my update, System.Configuration.ConfigurationManager is the class I use typically.

              – juunas
              Apr 22 '17 at 12:18





              Check my update, System.Configuration.ConfigurationManager is the class I use typically.

              – juunas
              Apr 22 '17 at 12:18




              2




              2





              Note that during development you will need to set these configuration values in local.settings.json.

              – Jaime Hablutzel
              Dec 15 '17 at 6:05





              Note that during development you will need to set these configuration values in local.settings.json.

              – Jaime Hablutzel
              Dec 15 '17 at 6:05













              28














              Note that for Azure Functions v2 this is no longer true.
              The following is from Jon Gallant's blog:



              For Azure Functions v2, the ConfigurationManager is not supported and you must use the ASP.NET Core Configuration system:




              1. Include the following using statement:



                using Microsoft.Extensions.Configuration;



              2. Include the ExecutionContext as a parameter



                public static void Run(InboundMessage inboundMessage, 
                TraceWriter log,
                out string outboundMessage,
                ExecutionContext context)



              3. Get the IConfiguration Root



                var config = new ConfigurationBuilder()
                .SetBasePath(context.FunctionAppDirectory)
                .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                .AddEnvironmentVariables()
                .Build();



              4. And use it to reference AppSettings keys



                var password = config["password"]


              When debugging locally, it gets the settings from local.settings.json under the "Values" keyword. When running in Azure, it gets the settings from the Application settings tab.






              share|improve this answer





























                28














                Note that for Azure Functions v2 this is no longer true.
                The following is from Jon Gallant's blog:



                For Azure Functions v2, the ConfigurationManager is not supported and you must use the ASP.NET Core Configuration system:




                1. Include the following using statement:



                  using Microsoft.Extensions.Configuration;



                2. Include the ExecutionContext as a parameter



                  public static void Run(InboundMessage inboundMessage, 
                  TraceWriter log,
                  out string outboundMessage,
                  ExecutionContext context)



                3. Get the IConfiguration Root



                  var config = new ConfigurationBuilder()
                  .SetBasePath(context.FunctionAppDirectory)
                  .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                  .AddEnvironmentVariables()
                  .Build();



                4. And use it to reference AppSettings keys



                  var password = config["password"]


                When debugging locally, it gets the settings from local.settings.json under the "Values" keyword. When running in Azure, it gets the settings from the Application settings tab.






                share|improve this answer



























                  28












                  28








                  28







                  Note that for Azure Functions v2 this is no longer true.
                  The following is from Jon Gallant's blog:



                  For Azure Functions v2, the ConfigurationManager is not supported and you must use the ASP.NET Core Configuration system:




                  1. Include the following using statement:



                    using Microsoft.Extensions.Configuration;



                  2. Include the ExecutionContext as a parameter



                    public static void Run(InboundMessage inboundMessage, 
                    TraceWriter log,
                    out string outboundMessage,
                    ExecutionContext context)



                  3. Get the IConfiguration Root



                    var config = new ConfigurationBuilder()
                    .SetBasePath(context.FunctionAppDirectory)
                    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                    .AddEnvironmentVariables()
                    .Build();



                  4. And use it to reference AppSettings keys



                    var password = config["password"]


                  When debugging locally, it gets the settings from local.settings.json under the "Values" keyword. When running in Azure, it gets the settings from the Application settings tab.






                  share|improve this answer















                  Note that for Azure Functions v2 this is no longer true.
                  The following is from Jon Gallant's blog:



                  For Azure Functions v2, the ConfigurationManager is not supported and you must use the ASP.NET Core Configuration system:




                  1. Include the following using statement:



                    using Microsoft.Extensions.Configuration;



                  2. Include the ExecutionContext as a parameter



                    public static void Run(InboundMessage inboundMessage, 
                    TraceWriter log,
                    out string outboundMessage,
                    ExecutionContext context)



                  3. Get the IConfiguration Root



                    var config = new ConfigurationBuilder()
                    .SetBasePath(context.FunctionAppDirectory)
                    .AddJsonFile("local.settings.json", optional: true, reloadOnChange: true)
                    .AddEnvironmentVariables()
                    .Build();



                  4. And use it to reference AppSettings keys



                    var password = config["password"]


                  When debugging locally, it gets the settings from local.settings.json under the "Values" keyword. When running in Azure, it gets the settings from the Application settings tab.







                  share|improve this answer














                  share|improve this answer



                  share|improve this answer








                  edited Nov 15 '18 at 3:20









                  KyleMit

                  59.2k37248412




                  59.2k37248412










                  answered Sep 18 '18 at 22:41









                  PitchmattPitchmatt

                  583158




                  583158





















                      6














                      You can use System.Environment.GetEnvironmentVariable like this:



                      var value = Environment.GetEnvironmentVariable("your_key_here")


                      This gets settings whenever you're working locally or on Azure.






                      share|improve this answer





























                        6














                        You can use System.Environment.GetEnvironmentVariable like this:



                        var value = Environment.GetEnvironmentVariable("your_key_here")


                        This gets settings whenever you're working locally or on Azure.






                        share|improve this answer



























                          6












                          6








                          6







                          You can use System.Environment.GetEnvironmentVariable like this:



                          var value = Environment.GetEnvironmentVariable("your_key_here")


                          This gets settings whenever you're working locally or on Azure.






                          share|improve this answer















                          You can use System.Environment.GetEnvironmentVariable like this:



                          var value = Environment.GetEnvironmentVariable("your_key_here")


                          This gets settings whenever you're working locally or on Azure.







                          share|improve this answer














                          share|improve this answer



                          share|improve this answer








                          edited Nov 15 '18 at 3:28









                          KyleMit

                          59.2k37248412




                          59.2k37248412










                          answered Nov 6 '18 at 11:50









                          DSpiritDSpirit

                          12614




                          12614



























                              draft saved

                              draft discarded
















































                              Thanks for contributing an answer to Stack Overflow!


                              • Please be sure to answer the question. Provide details and share your research!

                              But avoid


                              • Asking for help, clarification, or responding to other answers.

                              • Making statements based on opinion; back them up with references or personal experience.

                              To learn more, see our tips on writing great answers.




                              draft saved


                              draft discarded














                              StackExchange.ready(
                              function ()
                              StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f43556311%2freading-settings-from-a-azure-function%23new-answer', 'question_page');

                              );

                              Post as a guest















                              Required, but never shown





















































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown

































                              Required, but never shown














                              Required, but never shown












                              Required, but never shown







                              Required, but never shown







                              Popular posts from this blog

                              How to how show current date and time by default on contact form 7 in WordPress without taking input from user in datetimepicker

                              Syphilis

                              Darth Vader #20