. NET core Read Appsettings.json configuration

Source: Internet
Author: User

Official Document: HREF

In the old version of ASP, the global configuration of the project usually exists in the AppSettings of the Web. config, and it is only possible to use the configurationmanager.appsettings["foo" to take the variable named Foo. in ASP. NET core, the way to access the configuration file has changed a lot. However, the Web. config in ASP. NET core has been replaced by Appsettings.json, plus a lot of dependency injection (Dependency injection) in ASP., which makes the read configuration information different from before. The new framework takes a more flexible and extensible configuration. Official use: Options. Configurationextensions

First the NuGet package is introduced

Microsoft.Extensions.Options.ConfigurationExtensions
How to quote is Emmmm

Or:

Then add the custom data to the Appsettings.json file

Create a corresponding model

Then configure the Startup.cs in the

            // ADD functionality to inject ioptions<t>             Services. AddOptions ();            Services. Configure<AppSettings> (configuration.getsection ("AppSettings"));

Then, you can use it where you want to use it.

It's already been shown.

. NET core Read Appsettings.json configuration

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.