0

我仍然一遍又一遍地绊倒这个页面。只是无法让用户的用户名(使用电子邮件作为用户名)mysupport.aspx在她成功登录后显示在页面上。结果应该看起来像这样,电子邮件显示但它没有检索任何内容:

电子邮件:   barb@hotmail.com

作为一个业余爱好者,我知道我错过了一大块拼图,但我不知道是什么。我是否错误地使用了mailLBL.Text = User.Identity.Name.ToString()?下面是代码隐藏:

Imports System
Imports System.Collections.Generic
Imports System.Linq
Imports System.Web
Imports System.Web.UI
Imports System.Web.UI.WebControls
Imports System.Data.SqlClient

Partial Class mysupport
Inherits System.Web.UI.Page

Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

    Dim sConnection As New SqlConnection(ConfigurationManager.ConnectionStrings("TrackTicketsConnectionString2").ConnectionString)
    sConnection.Open()

    Dim cmdS As String = "Select Email from Users Where Deleted='N'"
    Dim cmdCheckmail As New SqlCommand(cmdS, sConnection)

    If Session("Ticket") IsNot Nothing Then
        mailLBL.Text = User.Identity.Name.ToString()
    Else
        Response.Redirect("SignIn.aspx")
    End If

End Sub
Protected Sub signinBTN_Click(ByVal sender As Object, ByVal e As EventArgs)
    Session("Ticket") = Nothing
    Response.Redirect("SignIn.aspx")
End Sub
End Class

任何帮助和指导都非常感谢!

4

1 回答 1

1

您首先可以做的是研究这些链接:

这段代码有几个问题。

旧代码:

Dim cmdS As String = "Select Email from Users Where Deleted='N'"
Dim cmdCheckmail As New SqlCommand(cmdS, sConnection)

If Session("Ticket") IsNot Nothing Then
    mailLBL.Text = User.Identity.Name.ToString()
Else
    Response.Redirect("SignIn.aspx")
End If

更正的代码:

  If Session("Ticket") Is Nothing Then
    Response.Redirect("SignIn.aspx")
  Else
    Dim cmdS As String = "Select Email from Users Where Deleted='N' AND Username=@Username"
    Dim cmdCheckEmail as new SqlCommand(cmdS, sConnection)
    cmd.AddParameters(new SqlParameter("@UserName", SqlDbType.VarChar).Value = Session("Ticket")
    Dim obj as Object = cmd.ExecuteScalar()
    If obj isNot Nothing
      mailLBL.Text = Convert.ToString(obj)
    End If
  End

我希望这会有所帮助。

于 2013-06-04T18:10:39.970 回答