DEV Community

Cesar Codes
Cesar Codes

Posted on


Using JSON and User Secrets configuration with Azure Functions

In my last post, I talked about how we can extend the FunctionsStartup class and override its Configure method to register services. In this post, I’ll share how to go about using User Secrets and JSON file configuration.

If you want to use User Secrets, you must first add the Microsoft.Extensions.Configuration.UserSecrets package from NuGet. This should also add a GUID in your project file. At this point, you can utilize User Secrets through Visual Studio or the .NET Cli as you normally would. One thing to note is that the code sample below calls the AddUserSecrets() method. If you’re not going to use user secrets, skip this step and remove the call to the method (line 16).

For utilizing a JSON file, you want to go ahead and create the JSON file and the code sample below should work.

Happy Coding,

Top comments (1)

lkurzyniec profile image
Łukasz Kurzyniec

You made User Secrets required, by sending false flag. I would make it optional by sending true flag. By this, after deploy it won't throw.

.AddUserSecrets(Assembly.GetExecutingAssembly(), true)

Super Useful CSS Resources

A collection of 70 hand-picked, web-based tools which are actually useful.
Each will generate pure CSS without the need for JS or any external libraries.