在我制作的一个简单网站上,我的用户登录和密码屏幕出现问题。它应该会导致一个在网格视图中显示 SQL 源的新页面,但是当我按下已部署网站中的提交按钮时没有任何反应。下面是我的代码,以及我的 default.aspx 和我的 userAdmin.aspx 的源代码。代码隐藏有问题吗?如果可以,请告诉我。谢谢!
Protected Sub butSubmit_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles butSubmit.Click
Dim myReader As Data.SqlClient.SqlDataReader
Dim mySqlConnection As Data.SqlClient.SqlConnection
Dim mySqlCommand As Data.SqlClient.SqlCommand
'Establish the SqlConnection by using the configuration manager to get the connection string in our web.config file.
mySqlConnection = New Data.SqlClient.SqlConnection(ConfigurationManager.ConnectionStrings("ConnectionString").ToString())
Dim sql As String = "SELECT password FROM MyUsers WHERE username = '" & Me.TextBox1.Text & "'"
mySqlCommand = New Data.SqlClient.SqlCommand(sql, mySqlConnection)
Try
mySqlConnection.Open()
myReader = mySqlCommand.ExecuteReader()
If (myReader.HasRows) Then
myReader.Read()
Dim password As String = myReader("password")
If (password = Me.TextBox2.Text) Then
'Open page with users and roles
Dim message As String = "Correct password"
Dim style As MsgBoxStyle = MsgBoxStyle.OkOnly
Dim title As String = "Authenticated"
MsgBox(message, style, title)
End If
End If
Catch ex As Exception
Console.WriteLine(ex.ToString())
Finally
If Not (myReader Is Nothing) Then
myReader.Close()
End If
If (mySqlConnection.State = Data.ConnectionState.Open) Then
mySqlConnection.Close()
End If
End Try
End Sub
结束类
用户管理源
<%@ Page Language="VB" MasterPageFile="~/master.master" AutoEventWireup="false" title="UserAdmin" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" Runat="Server">
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="navigation" Runat="Server">
<a href="Default.aspx">Default.aspx</a>
<br />
<br />
<a href="userAdmin.aspx">userAdmin.aspx</a>
<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="main" Runat="Server">
<asp:SqlDataSource ID="SqlDataSource1" runat="server"
ConnectionString="<%$ ConnectionStrings:ConnectionString %>"
SelectCommand="SELECT * FROM [MyUsers]"></asp:SqlDataSource>
<asp:GridView ID="UserRolesGrid" runat="server" DataSourceID="SqlDataSource1"
Width="399px" AutoGenerateColumns="False" DataKeyNames="id">
<Columns>
<asp:BoundField DataField="id" HeaderText="id" InsertVisible="False"
ReadOnly="True" SortExpression="id" />
<asp:BoundField DataField="user_logon_id" HeaderText="user_logon_id"
SortExpression="user_logon_id" />
<asp:BoundField DataField="user_full_name" HeaderText="user_full_name"
SortExpression="user_full_name" />
<asp:BoundField DataField="user_description" HeaderText="user_description"
SortExpression="user_description" />
<asp:BoundField DataField="user_password" HeaderText="user_password"
SortExpression="user_password" />
</Columns>
</asp:GridView>
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="footer" Runat="Server">
</asp:Content>
default.aspx 源
<%@ Page Language="VB" Debug="true" MasterPageFile="~/master.master" AutoEventWireup="false" CodeFile="Default.aspx.vb" Inherits="_Default" title="Untitled Page" %>
<asp:Content ID="Content1" ContentPlaceHolderID="header" Runat="Server">
<p style="text-align: center; color: white">
SAM PEPPARD</p>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="navigation" Runat="Server">
<a href="Default.aspx">Default.aspx</a>
<br />
<br />
<a href="userAdmin.aspx">userAdmin.aspx</a>
<br />
</asp:Content>
<asp:Content ID="Content3" ContentPlaceHolderID="main" Runat="Server">
    User Name
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
    Password <asp:TextBox ID="TextBox2"
runat="server" TextMode="Password"></asp:TextBox>
   
<asp:Button ID="butSubmit" runat="server" Text="Submit" />
</asp:Content>
<asp:Content ID="Content4" ContentPlaceHolderID="footer" Runat="Server">
</asp:Content>