[英]Session ASP.NET doesnt seem to work
I have the following code on my default.aspx 我在default.aspx上有以下代码
Label1.Text = Session("valueName").ToString()
And the following code on my login.aspx 以及我的login.aspx上的以下代码
Dim strCon As String = ConfigurationManager.ConnectionStrings("Goed").ConnectionString Dim strCon As String = ConfigurationManager.ConnectionStrings(“Goed”)。ConnectionString
'Create Connection String And SQL Statement
Dim strSelect As String = "SELECT COUNT(*) FROM tbl_LogIn WHERE Gebruiker = @Gebruiker AND Wachtwoord = @Wachtwoord"
Dim con As New SqlConnection(strCon)
Dim cmd As New SqlCommand()
cmd.Connection = con
cmd.CommandType = CommandType.Text
cmd.CommandText = strSelect
Dim Gebruiker As New SqlParameter("@Gebruiker", _
SqlDbType.VarChar)
Gebruiker.Value = TxtUs.Text.Trim().ToString()
cmd.Parameters.Add(Gebruiker)
Dim Wachtwoord As New SqlParameter("@Wachtwoord", _
SqlDbType.VarChar)
Wachtwoord.Value = TxtPw.Text.Trim().ToString()
cmd.Parameters.Add(Wachtwoord)
con.Open()
Dim result As Integer = DirectCast(cmd.ExecuteScalar(), Int32)
con.Close()
If result >= 1 Then
Response.Redirect("default.aspx")
Session("valueName") = TxtUs.Text.ToString()
Else
lblMsg.Text = "Gebruikers naam en of wachtwoord kloppen niet"
End If
End Sub
But it doesnt seem to help. 但它似乎没有帮助。 I don't get any error or whatso ever, any idea?
我没有得到任何错误或任何想法,任何想法?
The Redirect
method ends the execution, so you have to set the session variable before redirecting: Redirect
方法结束执行,因此您必须在重定向之前设置会话变量:
Session("valueName") = TxtUs.Text.ToString()
Response.Redirect("default.aspx")
you are redirecting before setting the session. 您在设置会话之前重定向。 you should first set the session and then redirect the page.
您应首先设置会话,然后重定向页面。
Or 要么
Your result variable is not 1 or bigger than 1. you should check that too 您的结果变量不是1或大于1.您应该检查它
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.