When i login with incorrect username and password then it redirect to webform2.aspx where i want to show message Wrong username and password
how i do that ?
i am trying below code but it is not working
protected void Button1_Click(object sender, EventArgs e)
{
if(loginmethod(txt_us.Text,txt_pwd.Text)!="NA")
{
FormsAuthentication.Initialize();
String strRole =Assignroles(txt_us.Text);
FormsAuthenticationTicket fat = new FormsAuthenticationTicket(1, txt_us.Text, DateTime.Now, DateTime.Now.AddMinutes(30), false, strRole, FormsAuthentication.FormsCookiePath);
Response.Cookies.Add(new HttpCookie(FormsAuthentication.FormsCookieName,
FormsAuthentication.Encrypt(fat)));
loginmethod(txt_us.Text, txt_pwd.Text);
Response.Redirect("WebForm2.aspx");
}
else
{
Label1.Text = ("Incorrect UserName/Password");
Label1.Visible = true;
}
txt_us.Text = "";
txt_pwd.Text = "";
}
private string loginmethod(string UserName, string Password)
{
try
{
login_class lg_class = new login_class();
Entities2 login = new Entities2();
string logn = Convert.ToString(lg_class.loginfu(UserName, Password).Rows[0]["id"]);
Session["ID"] = logn.ToString();
return (logn);
}
catch (Exception ex)
{
return (ex.Message.ToString());
}
}
What I have tried:
loginfu method
public DataTable loginfunction(string username,string password)
{
try
{
Entities2 lg = new Entities2();
List<sp_getlogin_result> gr = lg.SP_GetLogin(username, password).ToList();
DataTable dt = new DataTable();
dt.Columns.Add("id", typeof(string));
foreach (var l in gr)
{
dt.Rows.Add(l.id);
}
return dt;
}
catch (Exception)
{
throw new Exception();
}
}