Note that there are some explanatory texts on larger screens.

plurals
  1. POManaging Dynamic Website Settings Persisted in a Database
    text
    copied!<p>I am trying to create something to hold global site-wide settings in our ASP.NET website - things such as site name, google analytics account number, facebook url etc... The site can have multiple ‘brands’ or sub-sites associated with it, hence the sitguid column, we would also like to have the option to put them into groups, hence the group column – e.g. TEST and PRODUCTION (set via web.config appsetting).</p> <p>I do not want any of the KEY’s to be hardcoded anywhere, but I would like to be able to reference them as simply as possible in code, e.g. SiteSetting.getSetting(“SiteName”) (these may be used in templates (masterpages and such) that more junior devs will create)</p> <p>I would also like to be able to administer the existing settings in our admin console and to be able to create new settings.</p> <p>The datatype column is for the edit form so that the correct input element can be used, e.g. checkbox for bit types, text box for varchar etc...</p> <p>SiteSettings database table currently:</p> <pre><code> [sts_sitGuid] [uniqueidentifier] NOT NULL, -- tells us which site the setting is for [sts_group] [nvarchar](50) NOT NULL, -- used to group settings e.g. test/live [sts_name] [nvarchar](max) NULL, -- the display name of the setting, for edit forms [sts_alias] [nvarchar](50) NOT NULL, -- the name for the setting [sts_value] [nvarchar](max) NOT NULL, -- the settings value [sts_dataType] [nvarchar](50) NULL, -- indicates the control to render on edit form [sts_ord] [tinyint] NULL, -- The order they will appear in on the admin form </code></pre> <p>I am part way through having this working at the moment, but I am not happy with the way I have done it and would like any advice people here have that might help find the ‘right’ solution! I'm sure people have done this before me. (I would share what I have so far, but do not want to skew the answers in any particular way) All i'm looking for is an overview of how this might be best done, not looking for anyone to write it for me ;)</p> <p>I’ve done quite a bit of searching both here and Google and have not really found what I’m looking for, especially the ability to add new setting ‘definitions’ as well as editing the settings that exist.</p> <p>The system runs on ASP.NET using webforms, it's all written in c# and uses MSSQL 2008.</p> <p>As always, any help is very much appreciated!</p> <p><strong>EDIT</strong>: To clarify I am going to explain what I have built so far. I am dead set on storing all of this in SQL as we don't want web.config or other xml files or another database floating around since it'll give us more to do when we rollout the app to other customers.</p> <p>So far I have a SiteSettings class, this has a method GetSetting which i can call with GetSetting("SettingAlias") to get the value for "SettingAlias" in the DB. This class's constructor fetches all the settings for the current site from the database and stores those in a dictionary, GetSetting reads from that dictionary. All of that part I am happy with so far.</p> <p>The part I am struggling with is generating the edit form. The previous version of this used a webservice to get/set the settings and I am trying to continue using something similar to save work, but they were all defined in the code, such as GoogleAnalyticsID, Sitename etc... and each had a column in the database, the change I am making is to store these settings as ROWS instead (since then it's easier to add more, no need to change the schema &amp; all of the sitesettings class) Currently my SiteSettings class has a SiteSettingsEditForm method which grabs all the info from the db, creates a bunch of controls for the form elements, puts that in a temporary page and executes that, then passes the HTML generated to our management system via ajax. This feels wrong and is a bit clunky, and is the reason for posting it here, I am having trouble figuring out how to save this stuff back via the webservice, but more importantly generating a bunch of HTML by executing a page containing a load of form controls just feels like the wrong way to do it.</p> <p>So in summary I (think i) want to write a class to be able to cache &amp; read a handful of rows from a database table, and also give me an edit form (or give data to something else to generate the form) that is dynamic based on the contents of the same database table (e.g. where my type column is 'bit' I want a checkbox, where it is 'text' I want a text input)</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload