I have a few settings that need to be edited from the admin panel of the site I'm currently working on. I thought it makes sense to place those settings inside the web.config (or should I place them somewhere else?). So anyway, I'm trying to write the necessary code to do this, but I got stuck... This is the first time I actually needed to do this so... :) Here's what I've got so far:
appSettings section inside the 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's a class I'm trying to write to allow for easy retrieval and modification of 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 do I continue from here?
And by the way, how safe is it to place site settings inside the web.config? Should I be worried about anything?
Thank you.