Evgeni Dimitrov
Evgeni Dimitrov

Reputation: 22516

MVC 4 dedicated configuration file

I have to add some constants to MVC 4 project. Adding them to in web.config will work:

  <appSettings>
    <add key="MyConst1" value="123"/>
    <add key="MyConst2" value="321"/>
    <add key="MyConst3" value="234"/>
  </appSettings>

Is there a way to create separate config file for this constants?

Upvotes: 0

Views: 55

Answers (2)

Habib
Habib

Reputation: 223392

I guess you want to separate your appSettings from web.config, you can store them in a separate file and then specify that in your web.config under appSettings's configSource like:

<appSettings configSource="MySettings.config" />

and then you can have your settings in MySettings.config as:

<?xml version="1.0" encoding="UTF-8"?>
<appSettings>
    <add key="MyConst1" value="123"/>
    <add key="MyConst2" value="321"/>
    <add key="MyConst3" value="234"/>
</appSettings>

You may see: Using configSource to split configuration files

Upvotes: 3

Simon C
Simon C

Reputation: 9508

If you put your code snippet in a file called appSettings.config, you can simply reference that file in your web config:

<appSettings configSource="appSettings.config" />

Upvotes: 3

Related Questions