สอบถามเรื่องการ Log in asp.net c# ค่ะ

เรื่องคือ ทำโปรเจ็คจบโดยใช้เครื่องมือ visual studio 2012 asp.net 4.0
โดยเงื่อนไขคือ ถ้า username และ password ถูกต้อง ต้องตรวจสอบรหัสพนักงานค่ะ
ถ้าเป็น 1 = page_board.aspx , 2 =page_maintenance.aspx , 3 = page_checker.aspx ,4= page_admin.aspx ค่ะ
โค้ดไม่ error นะคะ แต่พอรัน แล้วพิพม์รหัสที่ถูกต้องก็จะเตือนว่าข้อมูลผิดค่ะ
โค้ดตามนี้นะคะ
ท่านผู้รู้ช่วยแนะนำด้วยค่ะ ขอบคุณมากค่ะ
เดาะบอล//file page_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.Data.SqlClient;
using System.Web.Configuration;

namespace WebAssetManagement
{
    public partial class page_login : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
        }

        protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
        {
            string username = Login1.UserName;
            string pwd = Login1.Password;
            string s;
            s = WebConfigurationManager.ConnectionStrings["ChartDatabaseConnectionString"].ConnectionString;
            SqlConnection con = new SqlConnection(s);
            con.Open();
            string sqlUserName ;
            sqlUserName = "SELECT USERNAME,PASSWORD FROM AM_EMPLOYEE  WHERE USERNAME ='" + username + "' AND PASSWORD ='" + pwd + "'";
            string position = "SELECT POSITION_ID FROM AM_EMPLOYEE";
            
            SqlCommand cmd = new SqlCommand(sqlUserName, con);
            string CurrentName;
            CurrentName = (string)cmd.ExecuteScalar();
            if (CurrentName != null)
            {
                Session["UserAuthentication"] = username;
               // Session.Timeout = 2;
                if (Convert.ToInt32(position) == 1)
                {
                    Response.Redirect("page_board.aspx");
                }
                else if (Convert.ToInt32(position) == 2)
                {
                    Response.Redirect("page_maintenance.aspx");
                }
                else if (Convert.ToInt32(position) == 3)
                {
                    Response.Redirect("page_checker.aspx");
                }
                else if(Convert.ToInt32(position) == 4)
                {
                    Response.Redirect("page_admin.aspx");
                }

            }
            else
            {
                Session["UserAuthentication"] = "";
            }
        }

        //private char cint(string p)
        //{
        //    throw new NotImplementedException();
        //}
    }
}

เดาะบอล//file page_login.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="page_login.aspx.cs" Inherits="WebAssetManagement.page_login" %>

<%@ Register src="ControlHead.ascx" tagname="ControlHead" tagprefix="uc1" %>

<%@ Register src="Controlfooter.ascx" tagname="Controlfooter" tagprefix="uc2" %>

<!DOCTYPE html>
<style type="text/css">
    
    .locat-style1 {
        vertical-align:central;
        color:#8B0000;
        font:bold;
        font-family:'Comic Sans MS';
        
    }
    .local-style2 {
       text-align:center;
    }

</style>
<html xmlns="http://www.w3.org/1999/xhtml">

<head runat="server">
    <title>log in</title>
    </head>
    
  
          
<body>          
          
<form id="form2" runat="server">
            
    <div id="form1" runat="server">
    
        <div class="local-style2">
            <uc1:ControlHead ID="ControlHead1" runat="server" ></uc1:ControlHead>
       </div>
        <div>
        
    <fieldset style="color: #990000; height: 400px; width: 1300px; margin-left: 10px;" class="locat-style1">
        <legend>ASSET MANAGEMENT
        </legend>
        <asp:Login ID="Login1" runat="server" Height="226px" style="margin-left: 406px; margin-top: 77px" Width="489px" CssClass="local-style2">
            <LayoutTemplate>
                <table style="border-collapse:collapse;">
                    <tr>
                        <td>
                            <table  style="height:226px;width:489px;">
                                <tr>
                                    <td  colspan="2" class ="local-style2">LOG IN</td>
                                </tr>
                                <tr>
                                    <td class="local-style2">
                                        <asp:Label ID="UserNameLabel" runat="server" AssociatedControlID="UserName">USER NAME :</asp:Label>
                                    </td>
                                    <td class="local-style2">
                                        <asp:TextBox ID="UserName" runat="server" Width="210px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="UserNameRequired" runat="server" ControlToValidate="UserName" ErrorMessage="User Name is required." ToolTip="User Name is required." ValidationGroup="ctl00$Login1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td class="local-style2">
                                        <asp:Label ID="PasswordLabel" runat="server" AssociatedControlID="Password">PASSWORD :</asp:Label>
                                    </td>
                                    <td class="local-style2">
                                        <asp:TextBox ID="Password" runat="server" TextMode="Password" Width="210px"></asp:TextBox>
                                        <asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password" ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="ctl00$Login1">*</asp:RequiredFieldValidator>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2"> </td>
                                </tr>
                                <tr>
                                    <td  colspan="2" style="color:#8B8682;" class ="local-style2">
                                        <asp:Literal ID="FailureText" runat="server" EnableViewState="False"></asp:Literal>
                                    </td>
                                </tr>
                                <tr>
                                    <td colspan="2" class="local-style2">
                                        <asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="ctl00$Login1" ></asp:Button>
                                    </td>
                                </tr>
                            </table>
                        </td>
                    </tr>
                </table>
            </LayoutTemplate>
        </asp:Login>
    </fieldset>



         </div>
                
        <div class="local-style2">
            <uc2:Controlfooter ID="Controlfooter1" runat="server" ></uc2:Controlfooter>
        </div>

  
    
    </div>
  
    </form>
</body>
</html>
แก้ไขข้อความเมื่อ
แสดงความคิดเห็น
โปรดศึกษาและยอมรับนโยบายข้อมูลส่วนบุคคลก่อนเริ่มใช้งาน อ่านเพิ่มเติมได้ที่นี่