How to access the session declared in Session_Start in Global.asax file in another class file in asp.net

1k views Asked by At
##Global.asax file ##

This is global.asax file for writing session variable

protected void Session_Start(object sender, EventArgs e){
    Session["myName"] = "something";        
    }

The class below is located in a separate library but in the same solution

    --------------------------------------------


    ## MyClass.cs ##

    using system.web;
    public class myclass{

        public string my method()
        {
            string x = httpcontext.current.Session["myName"];
            return x;
        }
    }

but here the session value is null. I am unable to populate the string.

Please let me know what I am doing wrong.

0

There are 0 answers