0

I am having two keys in my Web.Config file as follows

</configuration>
  <appSettings>
    <add key="PrimaryValue" value="hq6775"/>
    <add key="SecondaryValue" value="xVkP2355687"/>
  </appSettings>
</configuration>

I want to read these keys in my Controller method. Can any one help me on this?

  • 1
    Don't use web.config in ASP.Net Core, use a JSON file with your setting in. Read this: https://learn.microsoft.com/en-us/aspnet/core/fundamentals/configuration – DavidG Jul 31 '17 at 10:55
  • Answer in [Using app.config in .Net Core](https://stackoverflow.com/questions/45034007/using-app-config-in-net-core) valid for `web.config` file as well – Set Jul 31 '17 at 11:02

1 Answers1

1

ASP.Net Core app (web app / API) doesn't use web.config, it's needed by IIS only. You need web.config if you publish your app and host in IIS, however it should contain IIS related settings and app arguments only.

To store your configuration values, as Set suggested, you can use an XML config file, and name your file the way you like, however as DavidG suggested in comments, it would be a recommended approach to use a JSON config file.

Ignas
  • 4,092
  • 17
  • 28