SelAromDotNet
SelAromDotNet

Reputation: 4815

Using ConfigurationManager in Asp.net Core with .NET Framework website

When you create an ASP.NET Core website you have the option of using .NET Core or .NET Framework, depending on (among other things) whether or not your site will use .NET Framework components.

I need to reference a regular .NET Framework class library in my site, so I chose the .NET Framework option.

However, this class library makes use of appSettings defined in the app.config file. Now, if I place an app.config file in my ASP.NET Core website, and create an appSettings section and populate it with the fields I need, everything works.

However, these are sensitive keys (connection strings, etc.) so I want to be able to put them in an external file as described here: http://www.hanselman.com/blog/BestPracticesForPrivateConfigDataAndConnectionStringsInConfigurationInASPNETAndAzure.aspx

However, when I do this, I get an exception in the external library that the configuration setting is empty. I referenced the external file, which is in the same directory as the app.config in the root of the project (not the wwwroot folder) but the value always comes up empty. I tried putting the external config file in the wwwroot folder just out of desperation but that didn't work either.

The external reference works fine in the .NET Framework project as well as a console app I used to test it;only the .NET Core website seems to be unable to be able to handle it as an external reference. It only works if it's inside the app.config file directly.

Is pointing the configSource or file option for appSettings in app.config not supported in ASP.NET Core, or am I missing a step?

If it can't be done, how can I pass the necessary configuration over to the external class library which was not built with .net core?

EDIT: In summary: the class library is using System.Configuration, and NOT targeting .net core or standard.

I'm using a website in ASP.NET core on .NET Framework, and my problem is that app.config works, but ONLY if the appSettings are in the app.config file.

I want to move them to an external file (so the appSetting values are not checked into source) but this appears to not work.

My problem isn't that configuration doesn't work, it's that I can't put their values in a separate file.

Upvotes: 2

Views: 6150

Answers (1)

davidfowl
davidfowl

Reputation: 38764

.NET Core as of right now doesn't support System.Configuration, so you can't use the same approach as .NET Framework here. See https://learn.microsoft.com/en-us/aspnet/core/security/app-secrets for guidance on securing sensitive information in configuration during development

Upvotes: 3

Related Questions