473,320 Members | 1,955 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Store web.config value in SQL table

I have an application wide configuration setting (pages theme) that
is
dynamic. Normally when you think of picking themes you think of the
user selecting a theme (a per-user setting). In this case, though, I
want the site owner to be able to select a theme that will be applied
to the entire site (not per user). I do not want to programmatically
write out/edit the web.config file because of permissions issues. I
simply want the user to be able to set a value in a SQL table that
will then be grabbed (possibly in the Application_OnStart function in
global.asax) that will apply the theme to the entire site. This
isn't
something that would change often, but it has to an editable value
that is not static (like most things in web.config).

I was thinking there might be a way to programmitcally change the
<pages theme=""setting in web.config in Application_OnStart. Or is
there a way to bypass web.config entirely. I really don't want to
have to add code to every single Page_PreInit event)...
Thanks much.
Jack

Apr 18 '07 #1
1 2038
Hi Jack,

There are many different approaches to this (base class or master page), but
the easiest is to handle one application event in global.asax

void Application_Start(object sender, EventArgs e)
{
// retrieve the value from database;
Application[ThemeKey] = "red";
}

private const string ThemeKey = "DefaultTheme";

protected void Application_PreRequestHandlerExecute(
object sender, EventArgs e)
{
// this is the first event in which
// request handler is instantiated and accessible
Page page = HttpContext.Current.CurrentHandler as Page;
if (page != null)
{
page.Theme = Application[ThemeKey];
}
}

hope this helps
--
Milosz
"jack" wrote:
I have an application wide configuration setting (pages theme) that
is
dynamic. Normally when you think of picking themes you think of the
user selecting a theme (a per-user setting). In this case, though, I
want the site owner to be able to select a theme that will be applied
to the entire site (not per user). I do not want to programmatically
write out/edit the web.config file because of permissions issues. I
simply want the user to be able to set a value in a SQL table that
will then be grabbed (possibly in the Application_OnStart function in
global.asax) that will apply the theme to the entire site. This
isn't
something that would change often, but it has to an editable value
that is not static (like most things in web.config).

I was thinking there might be a way to programmitcally change the
<pages theme=""setting in web.config in Application_OnStart. Or is
there a way to bypass web.config entirely. I really don't want to
have to add code to every single Page_PreInit event)...
Thanks much.
Jack

Apr 18 '07 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: John Wildes | last post by:
hello I was wondering if someone could point me in the direction of information on using app.config to store string variables. I have a couple of variables that store path information for file...
2
by: mahesh.anjani | last post by:
hi i have stored my connction string in web.config as we do usually. code of web.confing is given below. check the password field contain "&" character. now when i run my application it gives...
10
by: Brett Romero | last post by:
I'd like to store something such as the following the my app.config file: <?xml version="1.0" encoding="utf-8" ?> <configuration> <appSettings> <add key="DEBUG" value="true"/> <add...
0
by: chefwiggum | last post by:
I have an application wide configuration setting (pages theme) that is dynamic. Normally when you think of picking themes you think of the user selecting a theme (a per-user setting). In this...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.