Saturday, March 31, 2012

Where do I put user changeable parameters now in 2.0? (global.asax)

Hi,
for some reason? I learnt it was sensible/useful to put any parameters
that I wanted users to be able to change in the global.asax file.
So my code would look like:
//in my page load
protected void Page_Load(object sender, System.EventArgs e)
{
myLabel.Text = (string) Application["PageHeading"];
string mydbfile = (string) Application["MDBDefault"];
string myLinkToUrl = (string) Application["DefaultWebpage"];
}
//in my global.asax file
<script language = "c#" runat="server">
protected void Application_OnStart()
{
Application["PageHeading"] = "Maths Production (2.0)";
Application["DefaultWebpage"] = "http://intranet";
Application["MDBDefault"] = "App_Data/YAS.mdb";
}
</script>
This worked well under .net 1.1 with precompiled aspx.cs files (as a
dll)
However, they've done it to me again and now I have to fix what wasn't
broken under 2.0
If I use the (afterthought) web deployment projects add in, I can
compile my codebehind, but it also compiles my global.asax and so my
customers can't set up the system parameters as they want to.
So how do I now do this? Please. (I'm not really hacked off - honest!
:( )
Regards
GordonAll these "configuration" values should either be database driven (if they
need to be managed through an interface) or simply in the web.config. This
is likely the best way in both 1.x and 2.x.
You can either simply use the AppSettings section, or write your own
configuration handler and have a little section to yourself:
http://openmymind.net/index.aspx?documentId=5
Karl
--
MY ASP.Net tutorials
http://www.openmymind.net/
http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
<gordonfmoore@.yahoo.co.uk> wrote in message
news:1134081712.633603.87070@.o13g2000cwo.googlegroups.com...
> Hi,
> for some reason? I learnt it was sensible/useful to put any parameters
> that I wanted users to be able to change in the global.asax file.
> So my code would look like:
> //in my page load
> protected void Page_Load(object sender, System.EventArgs e)
> {
> myLabel.Text = (string) Application["PageHeading"];
> string mydbfile = (string) Application["MDBDefault"];
> string myLinkToUrl = (string) Application["DefaultWebpage"];
> }
> //in my global.asax file
> <script language = "c#" runat="server">
> protected void Application_OnStart()
> {
> Application["PageHeading"] = "Maths Production (2.0)";
> Application["DefaultWebpage"] = "http://intranet";
> Application["MDBDefault"] = "App_Data/YAS.mdb";
> }
> </script>
> This worked well under .net 1.1 with precompiled aspx.cs files (as a
> dll)
> However, they've done it to me again and now I have to fix what wasn't
> broken under 2.0
> If I use the (afterthought) web deployment projects add in, I can
> compile my codebehind, but it also compiles my global.asax and so my
> customers can't set up the system parameters as they want to.
> So how do I now do this? Please. (I'm not really hacked off - honest!
> :( )
> Regards
> Gordon
>
Hey Gordon, read these [1],[2] and if I might nitpick shouldn't your
parameters be written using camel case, i.e. pageHeading and so on?
<%= Clinton Gallagher
METROmilwaukee (sm) "A Regional Information Service"
NET csgallagher AT metromilwaukee.com
URL http://metromilwaukee.com/
URL http://clintongallagher.metromilwaukee.com/
[1] http://msdn2.microsoft.com/library/2y3fs9xs(en-us,vs.80).aspx
[2]
http://msdn.microsoft.com/asp.net/c...serprofiles.asp
"Karl Seguin" <karl REMOVE @. REMOVE openmymind REMOVEMETOO . ANDME net>
wrote in message news:upAHwHF$FHA.3676@.tk2msftngp13.phx.gbl...
> All these "configuration" values should either be database driven (if they
> need to be managed through an interface) or simply in the web.config.
> This is likely the best way in both 1.x and 2.x.
> You can either simply use the AppSettings section, or write your own
> configuration handler and have a little section to yourself:
> http://openmymind.net/index.aspx?documentId=5
> Karl
> --
> MY ASP.Net tutorials
> http://www.openmymind.net/
> http://openmymind.net/redirector.aspx?documentId=51 - Learn about AJAX!
>
> <gordonfmoore@.yahoo.co.uk> wrote in message
> news:1134081712.633603.87070@.o13g2000cwo.googlegroups.com...
>
Thanks guys, that helped. I hadn't realised that web.config could be
used for this.
Clinton, you are probably right :)

0 comments:

Post a Comment