当前位置:  开发笔记 > 后端 > 正文

在使用asp.net登录重定向时需要帮助

如何解决《在使用asp.net登录重定向时需要帮助》经验,为你挑选了1个好方法。

我有登录页面的问题.如果我不输入用户名或密码,它应该说"请输入一个用户名或密码"而不是它去目的地页面我的意思是没有在登录字段输入任何东西如果我点击提交按钮它将欢迎页面实际上哪个不应该发生.

这是我的代码请有人告诉我我的错误在哪里:

public class Login
{
  public string str = ConfigurationManager.ConnectionStrings["ConnectionString"].ConnectionString.ToString();
    public int GetLogin(string UserName, string Password)
    {
      SqlConnection con = new SqlConnection(str);
      SqlDataAdapter da = new SqlDataAdapter("select * from Login where UserName='"+UserName+"' and Password='"+Password+"'",con);
 DataSet ds = new DataSet();
        da.Fill(ds);
        if (ds.Tables[0].Rows.Count > 0)
        {
            if ((ds.Tables[0].Rows[0].ItemArray[0].ToString() == UserName) && (ds.Tables[0].Rows[0].ItemArray[1].ToString() == Password))
            {
                return 1;
            }
            else
            {
                return 0;
            }
        }

        else
        {
            return -1;
        }
    }
Login.aspx.cs:
protected void BtnLogin_Click(object sender, EventArgs e)
    {
        Session["UserName"] = TxtUserName.Text;      

        Login lg = new Login();    

        if ((lg.GetLogin(TxtUserName.Text, TxtPassword.Text) == 1))
        {
            Response.Redirect("c1.aspx");

        }

        else if((TxtUserName.Text=="")&&(TxtPassword.Text==""))
        {
            Lbl1.Text = "Please Enter the UserName and Password";
        }

        else
        {

            Lbl1.Text = "Sorry,Invalid UserName or Password";
        }             

    }

Daniel Schaf.. 5

所有这些功能都已内置于ASP.NET中.

查看RequiredFieldValidator以验证您的字段,或使用Login Controls来处理所有表单功能.

查看FormsAuthentication和Membership以进行用户身份验证.



1> Daniel Schaf..:

所有这些功能都已内置于ASP.NET中.

查看RequiredFieldValidator以验证您的字段,或使用Login Controls来处理所有表单功能.

查看FormsAuthentication和Membership以进行用户身份验证.

推荐阅读
yzh148448
这个屌丝很懒,什么也没留下!
DevBox开发工具箱 | 专业的在线开发工具网站    京公网安备 11010802040832号  |  京ICP备19059560号-6
Copyright © 1998 - 2020 DevBox.CN. All Rights Reserved devBox.cn 开发工具箱 版权所有