0

I have made a little custom log-in page in asp.net, see code:

        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")
        Else
            lblMsg.Text = "Gebruikers naam en of wachtwoord kloppen niet"
        End If

    End Sub

As you can see it directs to Default.aspx.

On my defaults.aspx page I have a header. In this header I want a small label to sdhow the logged in user something like: Hello [User] How can this be done?

4

2 回答 2

2

使用会话:

定向到新页面时(在 Login.aspx-in 按钮的 onClick 事件中)

Session["valueName"]=value;

在新页面上(在您的情况下为 default.aspx)使用:

Label1.Text=Session["valueName"].ToString();

或者您也可以使用 cookie:

创造:

Response.Cookies("userInfo")("userName") = "DiederikEEn"
Response.Cookies("userInfo")("lastVisit") = DateTime.Now.ToString()
Response.Cookies("userInfo").Expires = DateTime.Now.AddDays(1)

阅读:

If Not Request.Cookies("userName") Is Nothing Then
    Label1.Text = Server.HtmlEncode(Request.Cookies("userName").Value)
End If

If Not Request.Cookies("userName") Is Nothing Then
    Dim aCookie As HttpCookie = Request.Cookies("userName")
    Label1.Text = Server.HtmlEncode(aCookie.Value)
End If

更多在这里:

  1. 饼干
  2. 会话
于 2013-04-25T08:48:02.063 回答
0

如果您可以在母版页中创建标题,那么您可以在 Hello [User] 那里添加并调用会话。

于 2013-04-25T08:44:47.933 回答