处理程序更改会话变量?

时间:2014-02-24 10:53:48

标签: asp.net vb.net session session-variables httphandler

我有这个处理程序:

Public Sub ProcessRequest(context As HttpContext) Implements IHttpHandler.ProcessRequest
    Dim request As HttpRequest = context.Request
    Dim response As HttpResponse = context.Response

    If (request.QueryString(GestioneConstants.PASSWORD_PARAM) Is Nothing) Then

        Dim erroreParamName = GestioneConstants.ERRORE_PASSWORD_PARAM
        Dim erroreMessage = GestioneConstants.MESSAGE_PWD_MANCANTE

        Dim urlHome = "~/Default.aspx?" & erroreParamName & "=" & erroreMessage

        response.Redirect(urlHome, False)
    Else
        Dim passToFind= request.QueryString(GestioneConstants.PASSWORD_PARAM)
        Dim myConn As OdbcConnection
        myConn = New OdbcConnection("Driver={Microsoft ODBC for Oracle};Server=SERVER;uid=uid;pwd=password")

        myConn.Open

        Dim passwordQuery As String = "SELECT PASSWORD as PASSWORD FROM INFOPWD WHERE INFOPWD.PASSWORD = '" & passToFind & "'"
        Dim queryCommand As OdbcCommand = New OdbcCommand(passwordQuery,myConn)


        Dim reader As OdbcDataReader = queryCommand.ExecuteReader()

        Dim risultato = ""
        While reader.Read()

            risultato = reader("PASSWORD").ToString

        End While

        reader.Close
        myConn.Close

        If (risultato Is "") Then
            Dim erroreParamName = GestioneConstants.ERRORE_PASSWORD_PARAM
            Dim erroreMessage = GestioneConstants.MESSAGE_PWD_ERRATA

            Dim urlHome = "~/Default.aspx?" & erroreParamName & "=" & erroreMessage

            response.Redirect(urlHome, False)
        Else

            context.Session("Logged") = True

            Dim strURL = "~/Home.aspx"

            response.Redirect(strURL, False)
        End If
    End If
End Sub

实际上我的问题是:

context.Session("Logged") = True

我只想将此会话变量设置为true,在ASP页面中,用户插入正确的密码。

但我收到错误:

An object reference not set to an instance of an object.

我不明白为什么会这样。

有人可以帮忙吗?

1 个答案:

答案 0 :(得分:0)

您需要使用Current属性: context.Current.Session("Logged") = True应该有用。