Read the configuration file and asp.net configuration file in ASP. NET 5.

Source: Internet
Author: User

Read the configuration file and asp.net configuration file in ASP. NET 5.

(This article is also published in my public account "dotNET daily excellent article". Welcome to the QR code on the right to follow it .)

In ASP. NET 5, the basic structure of the previous configuration file is abandoned, and a new configuration file system is introduced. The article recommended today briefly introduces this aspect.

Microsoft introduced a completely new configuration file infrastructure in the cross-platform runtime to be officially released. Based on this configuration system, it is never so easy to read content from multiple configuration files.

The configuration system not only supports configuration files in json, xml, and ini formats, but also supports reading content from environment variables. As follows:

var configuration = new Configuration()                            .AddJsonFile("config.json")                            .AddIniFile("config.ini")                            .AddXmlFile("config.xml")                            .AddEnvironmentVariables();

To support json files, Microsoft. framework. configurationModel. json namespace. xml files are supported and Microsoft. framework. configurationModel. xml, while the INI file requires the introduction of Microsoft. framework. configurationModel.

For json configuration files like the following:

{    "Data": {        "DefaultConnection": {             "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=DbName;Trusted_Connection=True;MultipleActiveResultSets=true"        }    }}

Reading the content is very simple:

var connectionString = configuration.Get("Data:DefaultConnection:ConnectionString");

"Read the original text" you can browse the original text (the original content is also relatively simple, almost like this ).

Address: http://blog.developers.ba/read-config-file-in-asp-net-vnext/

Related Article

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.