Read Appsettings.json

Source: Internet
Author: User

Appsettings.json configuration:

A configuration file is a JSON file, and is a strict JSON file, all attributes need to be added "" quotation marks. is a regular code example:

{"urlstring": {    //"URL": "/http//" 27.151.14.174: 8282/apiweb/? "    " URL " " http://172.28.40.122:8080/apiweb/? "   }}
Defining entities:

Getting the information inside the Appsettings.json needs to define the corresponding model to get the data. Such as:

public class URLString    {public        string Url {get; set;}    }
Read configuration information at startup:

Read the configuration information in the startup Configureservices method. Such as:

 Public void configureservices (iservicecollection services)        {            //  ADD Framework services.             Services. Addmvc ();             // Read configuration information            Services. Configure<urlstring> (this. Configuration.getsection ("urlstring"
}
The implementation class calls the implementation of the business, which is accessed through the constructor to get configuration information:
 Public classDatacenterappservice:sanfuappservicebase, idatacenterappservice{//Define tired     Private ReadOnlyIoptions<urlstring>_appconfiguration;  PublicDatacenterappservice (ioptions<UrlString>_appconfiguration) {             This. _appconfiguration =_appconfiguration; } Public stringGetstr () {return_appconfiguration.value.url;}}

  

Read Appsettings.json

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.