简体   繁体   中英

How to read Connection String provided in IIS from ASP.NET Core 2.1?

I'm trying to deploy to IIS on Windows Server 2016. The SQL Server connection string is saved in IIS Connection Strings.

How do I read the connection string from the ASP.NET Core 2 app in startup.cs?

I'm trying to avoid hard coding the string as well avoiding putting it in appsetting.json.

The ConfigurationManager class enables you to access machine, application, and user configuration information (from = Microsoft Docs ).

So, you can read the Server connection strings using:

string connString = System.Configuration.ConfigurationManager.ConnectionStrings["IISConnection"].ConnectionString;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM