How to get the Global variable Declared in the Global.asax File

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • baburmm
    New Member
    • Sep 2008
    • 12

    How to get the Global variable Declared in the Global.asax File

    Hai,
    I want to get the Global static name(for Constant) Declared in the Global.asax file for my whole project as a constant.
    my coding in the Global.asax file is

    private static string strName = "ABCD";
    public static string Names
    {
    get { return strName ; }
    }

    or is there any way to Declare the Global constant variable for the whole project in asp.net

    thanks in advance

    Regards,
    Babu.k
  • balabaster
    Recognized Expert Contributor
    • Mar 2007
    • 798

    #2
    Normally you would declare such things in the web.config. Constants and variables declared in the ASAX file are supposed to be for use only within that file.

    If you wish to declare variables that can be accessed outside this file you should declare them as such:

    Session("MyVari able") = MyObject

    or

    Application("My Variable") = MyObject

    Depending on whether you want the variables set at the session level or the application level.

    You would then reference them in the same manner from your MASTER/ASPX/ASCX

    Comment

    • baburmm
      New Member
      • Sep 2008
      • 12

      #3
      Thanks but it does nt works


      Originally posted by balabaster
      Normally you would declare such things in the web.config. Constants and variables declared in the ASAX file are supposed to be for use only within that file.

      If you wish to declare variables that can be accessed outside this file you should declare them as such:

      Session("MyVari able") = MyObject

      or

      Application("My Variable") = MyObject

      Depending on whether you want the variables set at the session level or the application level.

      You would then reference them in the same manner from your MASTER/ASPX/ASCX

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by baburmm
        Thanks but it does nt works
        Better give a better description than that.
        What did you try and what happened when you tried it?

        Comment

        • balabaster
          Recognized Expert Contributor
          • Mar 2007
          • 798

          #5
          Originally posted by r035198x
          Better give a better description than that.
          What did you try and what happened when you tried it?
          OP: Are you coding in C# or VB? In C# you'd reference them:

          Session["MySessionValue "] = "Some value";

          or

          Application["MyApplicationV alue"] = "Some value";

          Comment

          • baburmm
            New Member
            • Sep 2008
            • 12

            #6
            Thanks friends it works
            Originally posted by balabaster
            OP: Are you coding in C# or VB? In C# you'd reference them:

            Session["MySessionValue "] = "Some value";

            or

            Application["MyApplicationV alue"] = "Some value";

            Comment

            Working...