登录错误消息无效。 [英] Login Error message not working.

查看:88
本文介绍了登录错误消息无效。的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一条未显示的登录错误消息。如果您输入错误的用户名和密码,表单只会清除密码文本框,并且不会显示错误消息。有什么我忘了做的或者我错过了什么吗?



I have a login error message that is not showing up. If you enter the wrong username and password the form just clears out password textbox and will not show the error message. Is there something i forgot to do or am I missing something?

using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Configuration;
using System.Data;


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

    }
    protected void Button1_Click(object sender, EventArgs e)
    {

        SqlConnection con = new SqlConnection(System.Configuration.ConfigurationManager.ConnectionStrings["PasswordConnectionString"].ConnectionString);
        con.Open();



        if (true)
        {
            SqlCommand level = new SqlCommand("select INST_ID, AccessLevel, Password from TableSecurity where EmailAddress = @EmailAddress AND Password = @Password", con);
            level.Parameters.Add(new SqlParameter("EmailAddress", TextBoxEA.Text));
            level.Parameters.Add(new SqlParameter("Password", TextBoxPW.Text));

            SqlDataReader reader = level.ExecuteReader();
            DataTable dt1 = new DataTable();
            dt1.Load(reader);

            foreach (DataRow dr1 in dt1.Rows)
            {
                int returnedLevel = Convert.ToInt32(dr1[0].ToString());

                if (returnedLevel == 1)
                {
                    Response.Redirect("FormAPublic.aspx");
                }
                else if (returnedLevel == 2)
                {
                    Response.Redirect("FormCPrivateNon.aspx");
                }
                else if (returnedLevel == 3)
                {
                    Response.Redirect("FormDPrivateFor.aspx");
                }
                else if (returnedLevel == 7)
                {
                    Response.Redirect("CEOPage.aspx");
                }
                else if (returnedLevel == 8)
                {
                    Response.Redirect("DBPage.aspx");
                }
                else  
                {
                    Label1.Text = "Invalid UserName and Password!!!";
                }
                con.Close();
            }
        }
    }
}

推荐答案

您指定的列索引因为Datarow似乎是错的。



The column index you have specified for the Datarow seems to be wrong.

int returnedLevel = Convert.ToInt32(dr1[0].ToString());





将索引更改为1而不是0 // 0,因为选择查询是针对INST_ID



另外,使用否则只是为了检查它是否显示错误1,2,3,7,8未返回



请检查并还原。希望这有帮助......



Change the index to 1 instead of 0 // 0 as per the select query is for INST_ID

Also,use else instead of elseif just to check whether the it shows the error incase 1,2,3,7,8 not returned

Please check and revert . Hope this helps...


这篇关于登录错误消息无效。的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆