Can I use a Session variable in a function

When a user logs in to my system, the string for the connection to the database is pulled out of a table and stored in a Session Variable.  For my function to have the correct connection string in saving to the database, I want to be able to use the string stored in the Session Variable. 

In a normal Subroutine, I can use strConnection = Session("ConnectionString")

But wth a function, I don't have this option.  I could feed the connection string in as a parameter when calling the function, but don't want to do that. 

How can I get the session variable when calling a function.

0
JAYHAWKER
5/2/2009 3:36:29 PM
asp.net.state-management 8807 articles. 0 followers. Follow

4 Replies
962 Views

Similar Articles

[PageSpeed] 7

Your class files will need a reference to the System.Web assembly.

You can access curent Session via:
System.Web.HttpContext.Current.Session["ConnectionString"];


Om Prakash
0
om_prakashp
5/2/2009 4:24:13 PM

Hi,

I may be wrong but are you trying to use session variable in another class or code file besides the page? Try using the the line below...

ConnectionString = System.Web.HttpContext.Current.Session("ConnectionString").ToString()

Apologies if I am wrong....


[Please mark the post as answer that helps you.]

Regards,
Farhan Uddin Khan
Enpointe Technologies
0
FarhanK
5/2/2009 4:27:49 PM

Hi,

When you say function, are you talking about a client side function like JavaScript or a server side function?


Sincerely,
Malcolm Sheridan
Microsoft Certified Solution Developer
Please remember to click "Mark as Answer" on the post that helps you, and to click "Unmark as
Answer" if a marked post does not actually answer your question.
0
malcolms
5/3/2009 12:35:46 AM

Thanks for the reply.

I am using VS 2008, VB, server side function

0
JAYHAWKER
5/3/2009 3:25:38 AM
Reply: