Saturday, March 24, 2012

Session variable problem

Hi,

Im having trouble with the code below, I think it is because this code is executed in a class and not on an actual form, I am getting the error "Name 'Session' is not declared.

Is there away to fix this error? Is there an problems with setting the user session variable in a class and not on a form?

Private Function PasswordMatch(ByVal UserName, ByVal PassEntered)
Try
Dim intResult As Integer = 0
Dim intUser As Integer
SqlCmdLogon.CommandText = "sp_CheckPassword"
SqlCmdLogon.Parameters("@dotnet.itags.org.Username").Value = UserName
SqlCmdLogon.Parameters("@dotnet.itags.org.Password").Value = PassEntered
SqlCnnShippers.Open()
SqlCmdLogon.ExecuteNonQuery()
intResult = SqlCmdLogon.Parameters("@dotnet.itags.org.Rows").Value
intUser = SqlCmdLogon.Parameters("@dotnet.itags.org.UserID").Value
If intResult = -1 Then

session("UserID") = SqlCmdLogon.Parameters("@dotnet.itags.org.UserID").Value

Return True
Else
Return False
End IfApparently it is not possible, so passed it to a public readonly property instead then called that on the form to set the session variable instead.

Should be Ok.

I'll mark resolved but if anyone sees aproblem ps let me know.
Can i know how we check there is what stored inside the session?
Session("Name") ="Fish"
label1.text = Session("Name")
'Label should display "Fish"
Apparently it is not possible, so passed it to a public readonly property instead then called that on the form to set the session variable instead.

Should be Ok.

I'll mark resolved but if anyone sees aproblem ps let me know.
That's how it was supposed to be done. You can't let your HTTPContexts be mixed into your class logic.

0 comments:

Post a Comment