ASP.NET C# で奇妙な問題が発生しています。
選択ドロップダウンの最初のオプションとは別に、他のオプションを使用してログインできるようです。データベースのパスワードを確認しましたが、正しいものです。
なぜこれが事実なのか誰にも分かりますか?
これが私のコードです:
ログイン.aspx
<form id="loginForm" runat="server">
<asp:Login runat="server" OnAuthenticate="Login1_Authenticate" Width="293px" Height="172px"
ID="Login_Box">
<LayoutTemplate>
<!-- department -->
<div id="dept" style="text-align: left">
Department<br />
<asp:DropDownList ID="UserName" runat="server" DataSourceID="SqlDataSource1" DataTextField="dept"
DataValueField="id" DataMember="DefaultView">
</asp:DropDownList>
<asp:SqlDataSource ID="SqlDataSource1" runat="server" ConnectionString="<%$ ConnectionStrings:team13ConnectionString %>"
SelectCommand="SELECT [id], [dept] FROM [ts_dept] ORDER BY [dept]"></asp:SqlDataSource>
</div>
<!-- password -->
<div id="pass" style="text-align: left">
Password:<br />
<asp:TextBox ID="Password" runat="server" TextMode="Password"></asp:TextBox>
<asp:RequiredFieldValidator ID="PasswordRequired" runat="server" ControlToValidate="Password"
ErrorMessage="Password is required." ToolTip="Password is required." ValidationGroup="Login1"
ForeColor="Red" Display="Dynamic">Password is required.</asp:RequiredFieldValidator>
</div>
<!-- failure text -->
<div style="text-align: left; color: Red">
<asp:Literal ID="FailureText" runat="server" EnableViewState="False" Mode="Encode"></asp:Literal>
</div>
<br />
<!-- sign in button -->
<div class="btn" style="float: right" runat="server">
<asp:Button ID="LoginButton" runat="server" CommandName="Login" Text="Log In" ValidationGroup="Login1"
CssClass="cupid-green"/>
</div>
</LayoutTemplate>
</asp:Login>
</form>
ログイン.aspx.cs
using System;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using System.Web.Configuration;
public partial class login : System.Web.UI.Page
{
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login_Box.UserName;
string pwd = Login_Box.Password;
string strConn;
strConn = WebConfigurationManager.ConnectionStrings["team13ConnectionString"].ConnectionString;
SqlConnection Conn = new SqlConnection(strConn);
Conn.Open();
string sqlUserName;
sqlUserName = "SELECT id,pass FROM ts_dept ";
sqlUserName += " WHERE (id ='" + username + "')";
sqlUserName += " AND (pass ='" + pwd + "')";
SqlCommand com = new SqlCommand(sqlUserName, Conn);
string CurrentName;
CurrentName = (string)com.ExecuteScalar();
if (CurrentName != null)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("Default.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
}