Global.asax

Discussion in 'ASP.NET / ASP.NET Core' started by jgs3, Apr 1, 2005.

Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.
  1. Hello,

    I am looking for anybody who migh have an example of loading data from a database during the Application_Start in the Global.asax file. I simply want to pick the values from the DB and use them to set Application variables for all my pages to use. I was trying to use static variables [cache("varName") = varValue] but couldn't get that to work either. ANy hepl would be appreciated...

    Jim
     
  2. Jim, you are not going to accomplish what you are looking for by declaring local variable in the Application_Start method. You can either declare them Public Static at a class level or you can use Session variables. </o:p>
    If you declare them at the class level (Public Static) you are going to need to instantiate the Global class any time you want to use them.</o:p>
    Please let me know if you need more details.</o:p>


    Marcelo.
     
  3. Thanks but the Application variables are working when set in Global.asax as in:


    <%@ Import Namespace="System.Web.Caching" %>


    <script language="vb" runat="server">
    Sub Application_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the application is started
    Application("AllUniqueSessions") = 0
    Application("NextPrezCon") = #02/22/2006#
    Application("gmcutoff") = #09/30/2005#
    Application("playercutoff") = #01/30/2006#


    End Sub


    Sub Session_Start(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session is started
    Application("AllUniqueSessions") += 1
    End Sub


    Sub Session_Stop(ByVal sender As Object, ByVal e As EventArgs)
    ' Fires when the session is stopped
    Application("AllUniqueSessions") -= 1
    End Sub
    </script>

    I was looking for examples of how to load the values into the Application variables upon Application_Start.
     
Thread Status:
Threads that have been inactive for 5 years or longer are closed to further replies. Please start a new thread.

Share This Page