Re: How to declare a variable in the global scope?

From: Juan T. Llibre [MVP] (nomailreplies_at_nowhere.com)
Date: 12/16/04


Date: Thu, 16 Dec 2004 11:19:57 -0400

Hi, Miguel.

Kevin is right.

The web.config file's contents are loaded
into memory into the current AppDomain.

As soon as an Application starts, the configuration file
is loaded into memory, its contents are parsed and calls
are made to the relevant methods to register the objects
described in the file.

re:
> the change of value I do in my script on page_load doesn't change the
> default value?

No.

It only changes the variable instance's value.
The default value ( declared in web.config ) is unchanged.

You'd have to modify the web.config file itself,
in order to change the value of a variable set in it.

As soon as you save the changes to the new web.config,
the file will be reloaded and the changes registered.

Juan T. Llibre
===========
"Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in message
news:Oz3Da634EHA.3368@TK2MSFTNGP10.phx.gbl...
> Hi Kevin,
>
> I am not sure. If it is like that u mean that the change of value I do in
> my script on page_load doesn't change the default value?
>
> Thanks,
> Miguel
>
> "Kevin Spencer" <kspencer@takempis.com> wrote in message
> news:kspencer@takempis.com:
>> web.config is loaded into memory when the app starts, isn't that
>> correct?
>>
>> --
>> HTH,
>> Kevin Spencer
>> .Net Developer
>> Microsoft MVP
>> Neither a follower
>> nor a lender be.
>>
>> "Steve C. Orr [MVP, MCSD]" <Steve@Orr.net> wrote in message
>> news:e9FbFuv4EHA.3092@TK2MSFTNGP10.phx.gbl...
>> > Accessing the web.config is rather slow.
>> > Application is faster because it's all in memory and doesn't need to
>> access
>> > the hard drive. (except maybe it's not fast when the server is under
>> > heavy
>> > load.)
>> >
>> > --
>> > I hope this helps,
>> > Steve C. Orr, MCSD, MVP
>> > http://Steve.Orr.net
>> >
>> >
>> >
>> > "Juan T. Llibre [MVP]" <nomailreplies@nowhere.com> wrote in message
>> > news:uBb0Pdg4EHA.1452@TK2MSFTNGP11.phx.gbl...
>> > > Steve,
>> > >
>> > > Doesn't serializing the access to the Application object
>> > > using the Lock and UnLock methods mean you have to
>> > > accept a considerable performance hit ?
>> > >
>> > > It seems to me that, although using the Application object
>> > > gets the job done, it does so in a very inefficient way.
>> > >
>> > > That's why I suggested adding a key in web.config,
>> > > and retrieving *that* whenever needed.
>> > >
>> > >
>> > >
>> > > Juan T. Llibre
>> > > ===========
>> > > "Steve C. Orr [MVP, MCSD]" <Steve@Orr.net> wrote in message
>> > > news:u50RPXg4EHA.3292@TK2MSFTNGP10.phx.gbl...
>> > >> 'To store a variable:
>> > >> Application.Lock()
>> > >> Application("MyVar")="whatever"
>> > >> Application.Unlock()
>> > >>
>> > >> 'to retrieve the variable:
>> > >> Dim s as String = Application("MyVar").ToString()
>> > >>
>> > >> --
>> > >> I hope this helps,
>> > >> Steve C. Orr, MCSD, MVP
>> > >> http://Steve.Orr.net
>> > >>
>> > >>
>> > >> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in
>> message
>> > >> news:%23MQ$Zrc4EHA.1564@TK2MSFTNGP09.phx.gbl...
>> > >>> Hello,
>> > >>>
>> > >>> Can you tell me how to store the global variables in the
>> > >>> Application
>> > >>> Object?
>> > >>> What should the code be and where should I place it?
>> > >>>
>> > >>> I am just starting with ASP.NET.
>> > >>>
>> > >>> Thanks,
>> > >>> Miguel
>> > >>>
>> > >>> "Steve C. Orr [MVP, MCSD]" <Steve@Orr.net> wrote in message
>> > >>> news:Steve@Orr.net:
>> > >>>> With a web app, generally your global variables should be stored
>> > >>>> in
>> the
>> > >>>> Application Object or Cache object. This way they are explicity
>> > >>>> made
>> > >>>> accessible to all code in your app.
>> > >>>>
>> > >>>> --
>> > >>>> I hope this helps,
>> > >>>> Steve C. Orr, MCSD, MVP
>> > >>>> http://Steve.Orr.net
>> > >>>>
>> > >>>>
>> > >>>> "Miguel Dias Moura" <md*REMOVE*moura@*NOSPAM*gmail.com> wrote in
>> > >>>> message
>> > >>>>
>> > >>>> news:OPzDv2X4EHA.1524@TK2MSFTNGP09.phx.gbl...
>> > >>>> > Hello,
>> > >>>> >
>> > >>>> > I am working on an ASP.NET / VB page and I created a variable
>> > >>>> > "query":
>> > >>>> >
>> > >>>> > Sub Page_Load(sender As Object, e As System.EventArgs)
>> > >>>> > Dim query as String = String.Empty
>> > >>>> > ...
>> > >>>> > query = String.Format("SELECT * FROM dbo.documents WHERE ") &
>> query
>> > >>>> > End
>> > >>>> >
>> > >>>> > Sub
>> > >>>> >
>> > >>>> > I need "query" to be global and accessible everywhere.
>> > >>>> > How can I do this?
>> > >>>> >
>> > >>>> > Thanks,
>> > >>>> > Miguel
>> > >>>> >
>> > >>>
>> > >>
>> > >>
>> > >
>> > >
>> >
>> >
>