登录页面没有响应

时间:2014-03-03 19:32:41

标签: c# oracle visual-studio-2012

我的登录页面没有将我重定向到login.aspx.cs后面代码中写的任何其他页面。我按照教程设置了一个登录页面,该页面使用注册和基于角色来访问不同的页面。注册页面到目前为止工作正常,但登录没有响应。任何人都可以帮我解决这个问题。谢谢 Login.aspx.cs

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Xml.Linq;
using System.Data.OracleClient;

public partial class Account1_Login : System.Web.UI.Page
{
    string strConnString = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString;
    string str, User_Name, Password;
    OracleCommand com;
    OracleDataAdapter sqlda;
    DataTable dt;
    int RowCount;

    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void btn_login_Click(object sender, EventArgs e)
    {
        OracleConnection con = new OracleConnection(strConnString);
        con.Open();
        str = "Select * from users";
        com = new OracleCommand(str);
        sqlda = new OracleDataAdapter(com.CommandText, con);
        dt = new DataTable();
        sqlda.Fill(dt);
        RowCount = dt.Rows.Count;

        for (int i = 0; i < RowCount; i++)
        {
            User_Name = dt.Rows[i]["User_Name"].ToString();
            Password = dt.Rows[i]["Password"].ToString();
            if (User_Name == TextBox_user_name.Text && Password == TextBox_password.Text)
            {
                Session["User_Name"] = User_Name;

                if (dt.Rows[i]["userRole"].ToString() == "Admin")
                    Response.Redirect("Default.aspx");
                else if (dt.Rows[i]["userRole"].ToString() == "student")
                    Response.Redirect("Default.aspx");
                else if (dt.Rows[i]["userRole"].ToString() == "lecturer")
                    Response.Redirect("Default.aspx");
            }
            else
            {
                lb1.Text = "Invalid User Name or Password! Please try again!";
            }
        }
    }
}

Login.aspx页面

<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Login.aspx.cs" Inherits="Account1_Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">

    <title>Login</title>

    <script type="text/javascript" language="javascript">

        function Validate() {

            var User_Name = document.getElementById('TextBox_user_name');

            var Password = document.getElementById('TextBox_password');

            if ((User_Name.value == '') || (Password.value == '')) {

                alert('User_Name or Password should not be blank');

                return false;

            }

            else {

                return true;

            }

        }

    </script>

</head>

<body>

    <form id="form1" runat="server">

    <div>

    <asp:Label ID="lb1" runat="server" Font-Bold="True" ForeColor="#FF3300"></asp:Label><br />

     <asp:Label ID="Label1" runat="server" Text="Name" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>



        <asp:TextBox ID="TextBox_user_name" runat="server" ForeColor="#993300" Width="100px"></asp:TextBox><br />

        <asp:Label ID="Label2" runat="server" Text="Password" Font-Bold="True" Width="100px" BackColor="#FFFF66" ForeColor="#FF3300"></asp:Label>



        <asp:TextBox ID="TextBox_password" runat="server" ForeColor="#CC6600" TextMode="Password" Width="100px"></asp:TextBox><br />



        <asp:Button ID="btn_login" runat="server" Text="Login" Font-Bold="True"

            BackColor="#CCFF99"   OnClientClick="Validate()" onclick="btn_login_Click"

            /><br />

    </div>

    </form>

</body>

</html>

0 个答案:

没有答案
相关问题