我仍然一遍又一遍地绊倒这个页面。在成功登录后,用户的用户名(使用电子邮件作为用户名)无法显示在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
非常感谢任何帮助和指导!
答案 0 :(得分: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
我希望有所帮助。