Configure reading and editing inside Web.config

I have several settings that need to be edited from the admin panel of the site I'm currently working on. I thought it made sense to place these settings inside web.config (or should I place them somewhere else?). Anyway, I'm trying to write the necessary code to do this, but I'm stuck ... This is the first time I really needed to do this ... :) Here's what I still have:

appSettings section inside Web.config:

  <appSettings>
    <add key="ClientValidationEnabled" value="true" /> 
    <add key="UnobtrusiveJavaScriptEnabled" value="true" />
    <add key="InvitationOnly" value="true" />
    <add key="MaintainanceMode" value ="false"/>
  </appSettings>

And here is the class I'm trying to write to make it easier to find and change some values ​​that will be placed inside the appSettings section:

public static class SiteSettings
{
    public static bool InvitationOnly
    {
        get
        {
            var invitation = WebConfigurationManager.AppSettings["InvitationOnly"];
            return Convert.ToBoolean(invitation);
        } 
        set
        {
            Configuration config = WebConfigurationManager.OpenWebConfiguration("~");
            var appSettings = config.GetSection("appSettings") as AppSettingsSection;
            if(appSettings != null)
            {
                //got stuck here...
            }
        }
    }
}

Am I on the right track? How can I continue here?

And by the way, how safe is it to place site settings inside web.config? Should I worry about anything?

.

+3
1

web.config, , . web.config, ASP.NET AppDomain. Web.config , . , , web.config . , , cookie, ,...

+7

All Articles