ログイン後、データベースのテーブル登録からshow.aspxページにいくつかのデータを取得する必要があります。登録後に新しいユーザーを登録し、profile.aspxページにリダイレクトすると、すべての必要なデータが表示されます。私はログアウトしないと、再び同じユーザーにログインしない場合は、ページには何も私はユーザログインのためにこのコードを使用していセッションを使用しているユーザーのログインが動作しない
示さないshow.aspx:show.aspxページで
Protected Sub btnLogin_Click1(ByVal sender As Object, ByVal e As System.EventArgs)
Dim admin As String = "Admin"
Dim objcmd As New SqlCommand(("select * from Login where UserName='" + txtUserName1.Text & "' And Password='") + txtPassword1.Text & "'", con)
Dim objReader As SqlDataReader
con.Open()
objReader = objcmd.ExecuteReader()
If objReader.HasRows Then
While objReader.Read()
If [String].Compare(objReader("UserType").ToString(), admin) = 0 Then
Session("UserName_Admin") = txtUserName.Text.ToString().Trim()
Session("UserName") = txtUserName.Text.ToString().Trim()
Response.Redirect("adminview.aspx")
Else
Session("UserName") = txtUserName.Text.ToString().Trim()
Response.Redirect("show.aspx")
End If
End While
Else
lblLoginMessage.Text = "Login failed. Please try again"
End If
con.Close()
End Sub
コードを
Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)
If Session("UserName") Is Nothing Then
Response.Redirect("registration.aspx")
End If
binddata()
End Sub
Sub binddata()
Dim mycommand As New SqlCommand("SELECT * FROM registration where UserName = @UserName", con)
mycommand.Parameters.AddWithValue("@UserName", Session("UserName").ToString())
con.Open()
ProfileData.DataSource = mycommand.ExecuteReader
ProfileData.DataBind()
con.Close()
End Sub
Protected Sub LinkButton1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
Response.Redirect("upimg.aspx")
End Sub
私はデータリストを使用して、show.aspxページのデータベースからデータを取得しています。 web.configファイルで変更が必要なものはありますか?助けを歓迎します
私は*真剣*あなたは文字列にユーザー名とパスワードを連結しているコードのあなたの最初の部分を変更することをお勧めします。これは明確なSQLインジェクション攻撃の標的です。代わりにコードを使用して、パラメータ化されたクエリを使用します。 –