【问题标题】:Handler change Session Variable?处理程序更改会话变量?
【发布时间】:2014-03-25 23:48:14
【问题描述】:

我有这个处理程序:

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.

我不明白为什么会这样。

有人可以帮忙吗?

【问题讨论】:

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


【解决方案1】:

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

【讨论】:

  • 传递给ProcessRequest方法的context 参数“当前”上下文。 context.Current 所做的所有事情可能只是添加一个警告,说明通过实例而不是类型访问静态属性。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-03-23
  • 1970-01-01
  • 2012-03-08
相关资源
最近更新 更多