CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2
  1. #1
    Join Date
    Jul 2008
    Posts
    29

    Question how to create Global variable in project

    Hello!

    I am using ASP.NET 2.0 (Visual Studio 2005). There is one library having one class in which all my variables & functions are defined.

    I am referring this class library in my asp.net project.

    Now, I want to create an object of this class for every new session. So I will create this object in Session_Start() event in Global.asax. But, how will I access this object in entire project. for e.g.: in Default.aspx.vb and in other aspx.vb pages? How to make that class object which is defined in Session_Start() event global for entire project?

    Thank You.

  2. #2

    Re: how to create Global variable in project

    Probably the easiest thing to do is place it in the Session object -

    Code:
    MyObject obj = new MyObject();
    Session["myobj"] = obj;
    
    // Later code / methods:
    
    MyObject obj = (MyObject)Session["myobj"];
    
    // Make sure to add some error handling if the session expired / etc.
    Admittedly that's C#, but you should get the idea. Just make sure to properly handle the case of the session expiring and the return object being null.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured