登录asp.net问题 [英] login in asp.net issue

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

问题描述

任何人都可以解决我的问题..

这是我的btnLogin登录代码

hi can any one solve my problem..

here is my login code for btnLogin

protected void imgbtnLogin_Click(object sender, ImageClickEventArgs e)
   {
       LoginPL loginPL = new LoginPL();
       loginPL.UserName = txtUserName.Text;
       loginPL.Password = txtPassword.Text;

       LoginBLL loginBLL = new LoginBLL();
       bool loginSuccess;
       loginSuccess = loginBLL.Login(loginPL);
       if (loginPL.UserName=="admin" && loginPL.Password=="admin")

       {
           Response.Redirect("Admin/HomeUser.aspx");


       }
       else
       {
           //Response.Redirect("Tester/TesterWorkStatus.aspx");



           lblMessage.Text="Invalid Username / Password";
       }
       if (//how to give code here ......)
       {
           Response.Redirect("Tester/TesterWorkStatus.aspx");

       }
       else{
           lblMessage.Text="Invalid UserName/Password";
       }

   }


if(//如何在此处提供代码我的意思是,如果其他用户使用其登录名和密码登录,则它应该与表匹配并进行重定向..plea帮我解决了小问题.而且有许多用户想要从他们的用户名登录和密码,并且应该与sqltable匹配.任何人都可以解决此问题..

谢谢和问候..
fahad sheikhji


if(// how to give code here i mean if other user login with their login name and password it should match table and to redirect..plea help me for small problem.and there are many users so they want to login from their username and password and it should match sqltable..can any one solve this..

thanks and regards..
fahad sheikhji

推荐答案



您需要在BAL项目中创建一个功能.函数将根据插入的数据返回true/false.

因此,您的下一个if语句在其中需要该功能.那对你有用.

然后您的BAL函数将调用DAL函数以在数据库中搜索单个用户名和密码.如果存在,则它将返回true.

希望这些信息对您有帮助,

谢谢
-amit.
Hi,

you need to create one function in your BAL project. the function would return true/false depending upon your data that you insert.

So, your next if statement required that function in it. That will work for you.

and your BAL function will call DAL function for searching single username and password in database. if it is there then it will return true.

hope this information will helps you,

thanks
-amit.


protected void imgbtnLogin_Click(object sender, ImageClickEventArgs e) 
{ 
LoginPL loginPL = new LoginPL(); 
loginPL.UserName = txtUserName.Text;
 loginPL.Password = txtPassword.Text; 
LoginBLL loginBLL = new LoginBLL();
 bool loginSuccess; loginSuccess = loginBLL.Login(loginPL);
if(loginPL.UserName == "admin" && loginPL.Password == "admin")
 { Response.Redirect("Admin/HomeUser.aspx"); 
} 
else if(loginSuccess) 
{ 
Response.Redirect("Tester/TesterWorkStatus.aspx");
 }


在从文本框中检查登录名和密码之前,将sql表中的数据获取到datatable中,如图所示下面

before checking the login name and password from the textbox, get the data from the sql table into datatable as shown below

using (SqlCommand command = new SqlCommand("SELECT UserName, Password FROM TableName WHERE UserName = '" + txtUserName.Text + "' AND Password = '" + txtPassword.Text + "'", connection))
        {
        //
        // Invoke ExecuteReader method.
        //
            SqlDataReader reader = command.ExecuteReader();
            while (reader.Read())
            {
                if(reader.GetString(1) == txtUserName.Text && reader.GetString(2) == txtPassword.Text)
                {
                    Response.Redirect("Admin/HomeUser.aspx"); 
                }else
                {
                    //Invalid User
                    Response.Redirect("Tester/TesterWorkStatus.aspx");
                }
            }
        }


希望这会给您一个想法...


Hope this will give you an idea...


这篇关于登录asp.net问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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