Search code examples
asp.net-mvc-3implementationapplication-settings

MVC3 VS2010 Application Settings i9mplementation


I have an MVC2 C#.Net web app using VS2010. Below is an entry in y web.config:

<configuration>
     <applicationSettings>
       <BOE.My.MySettings>
         <setting name="AppBackColor" serializeAs="String">
           <value>AntiqueWhite</value>
         </setting>
       </BOE.My.MySettings>
     </applicationSettings>
</configuration>

However, in my Controler.cs file My.Settings.AppBackColor is unrecognized. Any ideas?

var backColor= My.Settings.AppBackColor

What am I doing wrong here?


Solution

  • That's Desktop application stuff. In web applications you don't use such settings.

    You could use the <appSettings> section of your web.config to store custom values:

    <appSettings>
        <add key="foo" value="bar" />
    </appSettings>
    

    and then when you want to read foo:

    var foo = ConfigurationManager.AppSettings["foo"];