I'm trying to create something to store global site settings on our ASP.NET website - things like site name, Google Analytics account number, facebook url, etc. A site can have several “brands” or “subcategories”, sites related to it, therefore we would also like to be able to put the sitguid column into groups, so the group column — for example, TEST AND PRODUCTION (installed using the web.config application appsetting).
I do not want any of the KEYs to be hardcoded anywhere, but I would like to be able to refer to them as easily as possible in the code, for example. SiteSetting.getSetting ("SiteName") (they can be used in templates (master pages, etc.), which will be created by younger developers)
I would also like to be able to administer existing settings in our admin console and create new settings.
The data type column is for the edit form so that you can use the correct input element, for example. checkbox for bit types, text box for varchar, etc.
SiteSettings Database Table:
[sts_sitGuid] [uniqueidentifier] NOT NULL, -- tells us which site the setting is for [sts_group] [nvarchar](50) NOT NULL, -- used to group settings eg 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
I partially participate in the fact that this is working at the moment, but I am not happy with the way I did it, and I would like some of them to have tips that could help find the right solution! I'm sure people did it in front of me. (I would share what I still have, but I do not want to distort the answers in any particular way). All I am looking for is an overview of how best to do this without looking for someone to write it for me; )
I did quite a bit of searching both here and Google, and actually did not find what I was looking for, especially the ability to add new settings, as well as edit existing settings.
The system runs on ASP.NET using webforms, everything is written in C # and uses MSSQL 2008.
As always, any help is much appreciated!
EDIT . To clarify, I'm going to explain what I have created so far. I am dead to save all this in SQL, because we don’t want the web.config or other xml files or another database to float, as this will give us more options when we deploy the application to other users.
So far I have the SiteSettings class, this one has the GetSetting method, which I can call using GetSetting ("SettingAlias") to get the value for "SettingAlias" in the database. This class constructor extracts all settings for the current site from the database and stores them in a dictionary, GetSetting reads from this dictionary. I am still satisfied with this whole part.
The part I'm struggling with is spawning an edit form. In the previous version, this used webservice to get / set parameters, and I try to continue to use something similar to saving work, but they were all defined in the code, for example, GoogleAnalyticsID, Sitename, etc .... and each of them had a column in the database the change I am doing is to save these parameters as ROWS (since then it has become easier to add more, no need to change the scheme and the whole sitesettings class). Currently, my SiteSettings class has a SiteSettingsEditForm method that grabs all the information from db, creates a bunch of controls for the form elements, puts them on a temporary page and does it, and then passes the HTML generated to our control system via ajax. This seems wrong and a little awkward, and the reason for posting it here, it’s hard for me to understand how to save this material through a web service, but more importantly, to create a bunch of HTML by executing the page containing the download, the management form just feels like a wrong way to do this is.
So, in general, I (I think) want to write a class to be able to cache and read several rows from the database table, and also give me an edit form (or provide data to something else to create the form), which is dynamic based on the contents of the same database table (for example, where is my column of type “bit.” I want to check the box where it is “text”, I want text input)