Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/html/71.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 无法使用数据库中的现有用户登录!-ASP.NET_C#_Html_Asp.net_Login - Fatal编程技术网

C# 无法使用数据库中的现有用户登录!-ASP.NET

C# 无法使用数据库中的现有用户登录!-ASP.NET,c#,html,asp.net,login,C#,Html,Asp.net,Login,我正在使用ASP.NET web应用程序,我已经完成了一个Login.aspx页面,但每当我尝试登录时,都不会发生任何事情!没有错误,但单击“登录”按钮后什么也没有发生!有什么需要帮忙的吗 Login.asp.cs代码: 以及Login.aspx代码: 你为什么不调试代码呢?好像是临时工1和代码只需关闭连接 顺便说一下,该代码有一些问题。对同一个查询调用两次是非常低效的。也许您可以从卖家处获取所有信息,然后从内存中的相同数据中询问用户和密码 检查temp的值,并尝试首先修剪用户名和密码。此代码对

我正在使用ASP.NET web应用程序,我已经完成了一个Login.aspx页面,但每当我尝试登录时,都不会发生任何事情!没有错误,但单击“登录”按钮后什么也没有发生!有什么需要帮忙的吗

Login.asp.cs代码:

以及Login.aspx代码:


你为什么不调试代码呢?好像是临时工1和代码只需关闭连接

顺便说一下,该代码有一些问题。对同一个查询调用两次是非常低效的。也许您可以从卖家处获取所有信息,然后从内存中的相同数据中询问用户和密码


检查temp的值,并尝试首先修剪用户名和密码。

此代码对SQL注入是开放的,而且,将密码以明文形式存储是非常糟糕的做法,就像您的应用程序所做的那样。除了mituw16的要点,你知道所有这些都有一个asp:Login控件,对吗?@mituw16是的,我知道密码,我稍后会更改它,但我需要让登录工作正常first@Seano666是的,但我必须定制一个,因为我有两种类型的用户login@user5067119有很多方法可以做到这一点,是的,如果不想向现有表中添加字段,则可以创建一个查找表,该表只包含用户id和登录类型字段,不管您决定是什么。然后在你的查询中加入这个。然后可以使用查找表登录类型,以便页面知道重定向某人的位置。调试后仍不工作!我在注册表中使用了相同的代码,效果很好,我不知道为什么不起作用!
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Data.SqlClient;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

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

        }

        protected void ButtonS_Click(object sender, EventArgs e)
        {

                SqlConnection conn = new SqlConnection(ConfigurationManager.ConnectionStrings["MyDatabase"].ConnectionString);
                conn.Open(); 
                string checkuser = "Select count(*) from Sellers where Username='" + TextBoxSUsername.Text + "'";
                SqlCommand com = new SqlCommand(checkuser, conn);
                int temp = Convert.ToInt32(com.ExecuteScalar().ToString());
                conn.Close();
            if (temp == 1)
            {
                conn.Open();
                string checkPasswordQuery= "Select Password from Sellers where Username='" + TextBoxSUsername.Text + "'";
                SqlCommand PassCon = new SqlCommand(checkPasswordQuery, conn);
                string password = PassCon.ExecuteScalar().ToString().Replace(" ","");
                if (password==TextBoxSPassword.Text)
                {
                    Session["New"] = TextBoxSUsername.Text;
                    Response.Write("DONE");

                }
                else { Response.Write("Wrong password "); }
            }
            conn.Close();

        }
<table>
    <tr>
        <td> Username</td>
        <td><asp:TextBox ID="TextBoxSUsername" runat="server" Height="25px" Width="157px"></asp:TextBox></td>
        <td><asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="TextBoxSUsername" ErrorMessage="must enter username  "></asp:RequiredFieldValidator></td>
    </tr>
    <tr>
        <td>Password</td>
        <td><asp:TextBox ID="TextBoxSPassword" runat="server" Height="25px" Width="157px"></asp:TextBox></td>
        <td><asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="TextBoxSPassword" ErrorMessage="must enter password"></asp:RequiredFieldValidator></td>
    </tr>
        <tr><td><asp:Button ID="ButtonS" runat="server" OnClick="ButtonS_Click" Text="Button"/></td></tr>
</table>