How can I use session in ASP class file?
For a piece of code that you don't have enough, in that you have wrapped everything in quotes, the string should be in strings
FROM#
string sql = "select a,b,c from XXX where userid=" + System.Web.HttpContext.Current.Session["uid"].ToString();
V. B.
Dim sql As String = "select a,b,c from XXX where userid=" & System.Web.HttpContext.Current.Session("uid").ToString()
It assumes that the uid of the session has already been set.
While considering the post header while this is a separate class, it might be better to pass values in the constructor of the class or set them in the properties of the object object rather than accessing the session from within the class! This would allow for better code testing if you need to test somewhere other than a web application such as a unit test.
NTN
Oneshot
a source to share
One possible problem:
Looking at the code you provided, you have a quoted current.session call, which means you are passing a string
System.Web.HttpContext.Current.Session ["UID"]. ToString ()
in a where clause, which means nothing in sql.
You need to add the value from the call to current.session to the sql string.
try ...
where userid='" & System.Web.HttpContext.Current.Session("uid").ToString() & "'"
** edit ** OneSHOT gave the same answer while I was writing mine ... :)
If you are trying to exchange session data between classic ASP and ASP.Net, it is not very easy, but doable.
See the following MSDN page for details: http://msdn.microsoft.com/en-us/library/aa479313.aspx
a source to share