Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to get session id from cs class file in asp.net

Status
Not open for further replies.

sweth

IS-IT--Management
Mar 2, 2002
98
IN
I am classing common function in c# class file in asp.net.
HttpContext.Current.Session.SessionID gives object reference not set to an instance error. However I could get session id from codebehind file

Please help.
 
Could you post the class with the function to return the sessionid, and how you call the function?
 
Thanks for your reply

The following is the function which I used to call from a class file


private void getUserInfo(string userid)
{

sqlDataAccess sda = new sqlDataAccess(ConfigurationSettings.AppSettings["constring"],"Global");



string sessid = HttpContext.Current.Session.Contents.SessionID;

object[] parameters = {userid,sessid};
DataSet ds = sda.executeSqlReturnDataSet("proc_getuserinfo",CommandType.StoredProcedure,parameters);


if (ds.Tables[0].Rows.Count >= 1)
{
_officeid = Convert.ToInt32(ds.Tables[0].Rows[0][0].ToString());
_username = ds.Tables[0].Rows[0][1].ToString();
_officename = ds.Tables[0].Rows[0][2].ToString();
_gid = ds.Tables[0].Rows[0][8].ToString();
_officeaddress = ds.Tables[0].Rows[0][9].ToString();
_pid=ds.Tables[0].Rows[0][10].ToString();
_slot=Convert.ToInt32(ds.Tables[0].Rows[0][11].ToString());
}

sda.cleanUp();
}



string sessid = HttpContext.Current.Session.Contents.SessionID;

I am getting error in the above line. Though I could pass session id from a web page. The above code will considerably save lots of line in main pages.

 
Could you show the code calling the function? I Created 2 different examples and didn't have any problems. Any other information you can think of would help.
 
Thanks for your help. We finally found out today we tried to get session id in Global.asax.cs file also. We removed that and from class file we could get session id.

Thanks for your quick response
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top