Global.asax On_Start Variables resetting

Discussion in 'ASP .Net Web Controls' started by Israel Ordonez Jr, Nov 18, 2003.

  1. Hi everybody,
    I am having a problem with an ASP.NET application i am working on. I new to
    ASP.NET so I'm not sure if I'm doing this right.

    I am working on a website that has an oil price listed throught several
    pages. In the global.asax file i have the following code.

    Sub Application_Start(ByVal sender As Object, ByVal e
    As EventArgs)
    ' Fires when the application is started
    Application("OilPrice") = "1.14"
    Application("PrePay") = "1.14"
    End Sub

    I reference these variables on other pages. Everything works correctly up to
    this point. I have another page were the price can be changed. Once a new
    price is changed it reflects on all pages. The problem is after a few hours
    or the next day. The price always resets to the "1.14" in the global.asax
    file. It was my understanding that the Application_Start event only occurs
    once, the first time the application is accessed.

    Is my assumption correct? If so what could be causing the variables to be
    reset? Thanks!
     
    Israel Ordonez Jr, Nov 18, 2003
    #1
    1. Advertising

  2. Israel Ordonez Jr

    Alvin Bruney Guest

    Any number of things can cause the application to reset. In your case, I
    suspect it may be the idle time causing the recycle event. After an idle
    period the app recycles. This is controlled in the machine config file and
    IIS management. One easy suggestion is to place code in the application_end
    event to store the data to disk , in the registry, in a cookie or somewhere
    persistent. In the application_start event, you would first set the default
    value, then check the store to see if it contains valid data, setting the
    value if it is other than the default value.

    One other suggestion, application object is provided for backward
    compatibility so you should try to avoid it's use. You may use a static
    variable or better yet wrap the variable in a class which knows how to store
    and retrieve values during application recycle events. The class approach is
    better because sooner or later, you may want other long lasting objects as
    well.

    regards
    --


    -----------
    Got TidBits?
    Get it here: www.networkip.net/tidbits
    "Israel Ordonez Jr" <> wrote in message
    news:...
    > Hi everybody,
    > I am having a problem with an ASP.NET application i am working on. I new

    to
    > ASP.NET so I'm not sure if I'm doing this right.
    >
    > I am working on a website that has an oil price listed throught several
    > pages. In the global.asax file i have the following code.
    >
    > Sub Application_Start(ByVal sender As Object, ByVal e
    > As EventArgs)
    > ' Fires when the application is started
    > Application("OilPrice") = "1.14"
    > Application("PrePay") = "1.14"
    > End Sub
    >
    > I reference these variables on other pages. Everything works correctly up

    to
    > this point. I have another page were the price can be changed. Once a new
    > price is changed it reflects on all pages. The problem is after a few

    hours
    > or the next day. The price always resets to the "1.14" in the global.asax
    > file. It was my understanding that the Application_Start event only occurs
    > once, the first time the application is accessed.
    >
    > Is my assumption correct? If so what could be causing the variables to be
    > reset? Thanks!
    >
    >
     
    Alvin Bruney, Nov 18, 2003
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. VSK
    Replies:
    1
    Views:
    834
    Alvin Bruney
    Jul 29, 2003
  2. Israel Ordonez Jr

    Global.asax On_Start Variables resetting

    Israel Ordonez Jr, Nov 18, 2003, in forum: ASP .Net
    Replies:
    4
    Views:
    2,431
  3. Daniel Bass
    Replies:
    2
    Views:
    6,964
    Daniel Bass
    Dec 31, 2003
  4. =?Utf-8?B?YmNoYXJsZXM=?=

    global.asax and global.asax.cs

    =?Utf-8?B?YmNoYXJsZXM=?=, Oct 4, 2004, in forum: ASP .Net
    Replies:
    5
    Views:
    914
    =?Utf-8?B?YmNoYXJsZXM=?=
    Oct 5, 2004
  5. Mark Rae

    Global.asax / Global.asax.cs in v2

    Mark Rae, May 23, 2006, in forum: ASP .Net
    Replies:
    6
    Views:
    3,211
    Mark Rae
    May 23, 2006
Loading...

Share This Page