【问题标题】:What namespace do I need to import in code behind vb asp.net to get a session value我需要在 vb asp.net 后面的代码中导入什么命名空间来获取会话值
【发布时间】:2017-07-27 18:48:16
【问题描述】:

这是我的代码,会话不工作,缺少什么? 问候

Imports System.Web
Imports System.Data
Imports System.Data.SqlClient

Partial Class _Default
    Inherits System.Web.UI.Page

End Class

Partial Class _Default
    Inherits System.Web.UI.Page

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
    End Sub
    Protected Sub btnSubmit_Click(ByVal sender As Object, ByVal e As EventArgs)
        Dim con As New SqlConnection(ConfigurationManager.ConnectionStrings("dbconnection").ConnectionString)

        con.Open()
        Dim cmd As New SqlCommand("select * from nfl where UserName =@username and Password=@password", con)
        cmd.Parameters.AddWithValue("@username", txtUserName.Text)
        cmd.Parameters.AddWithValue("@password", txtPWD.Text)
        Session["password"] =  txtPWD.Text;
        Dim da As New SqlDataAdapter(cmd)
        Dim dt As New DataTable()
        da.Fill(dt)
        If dt.Rows.Count > 0 Then
            Response.Redirect("Details.aspx")
        Else
            ClientScript.RegisterStartupScript(Page.[GetType](), "validation", "<script language='javascript'>alert('Invalid Username and Password')</script>")
        End If
    End Sub
End Class

【问题讨论】:

  • 您的 sn-p 中没有 session 对象。那你到底在问什么?
  • 我的意思是我需要为会话工作导入什么类?它被标记为错误
  • 错误信息是什么?
  • 会话["密码"] = txtPWD.Text;其标记的红色下划线

标签: asp.net .net vb.net


【解决方案1】:

你没有使用 C#。

这个:

Session["password"] = txtPWD.Text;

应该是:

Session("password") = txtPWD.Text

【讨论】:

    猜你喜欢
    • 2012-01-01
    • 2011-03-18
    • 1970-01-01
    • 2014-09-02
    • 2015-05-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-07-15
    相关资源
    最近更新 更多