2013-03-01 32 views
0

我在我製作的簡單網站上遇到了用戶登錄和密碼屏幕問題。它應該會導致一個新的頁面在網格視圖中顯示一個SQL源,但是當我按下部署網站中的提交按鈕時沒有任何反應。下面是我的代碼,以及我的default.aspx和我的userAdmin.aspx的源代碼。代碼隱藏有問題嗎?如果可以,請告訴我。謝謝!爲什麼用戶登錄和密碼在Visual Studio中加載下一頁?

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 

末級

useradmin源

<%@ 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"> 
&nbsp &nbsp User Name 
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox> 
&nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp; Password&nbsp<asp:TextBox ID="TextBox2" 
    runat="server" TextMode="Password"></asp:TextBox> 
    &nbsp&nbsp&nbsp&nbsp;&nbsp;&nbsp;&nbsp; 
<asp:Button ID="butSubmit" runat="server" Text="Submit" /> 
</asp:Content> 
<asp:Content ID="Content4" ContentPlaceHolderID="footer" Runat="Server"> 
</asp:Content> 

回答

0

匹配的密碼,您應該將瀏覽器重定向到新的頁面之後。

使用Response.Redirect(newpage)

+0

所以重定向會像這樣下嗎? MsgBox(message,style,title) Response.Redirect(userAdmin.aspx) – user1690599 2013-03-01 07:01:33

+0

我的意思是Response.Redirect(userAdmin.aspx)會在MsgBox(消息,樣式,標題)之下? – user1690599 2013-03-01 07:08:18

+0

這會做的伎倆!謝謝! – user1690599 2013-03-01 07:38:41

相關問題