i want to redirect to other page like if user enter admin credential then he must be redirected to admin home page. and if user is non admin then he must be redirected to user home page in c#.
i have created one table with the filed
UId UName Pwd Type
1 ABC ABC123 ADMIN
2 XYZ XYZ123 USER
i have tried to write code as below:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=MySampleDB;Integrated Security=True;Pooling=False");
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=MySampleDB;Integrated Security=True;Pooling=False");
protected void Button1_Click(object sender, EventArgs e)
{
con.Open();
SqlDataAdapter ad = new SqlDataAdapter("select UName,Pwd,Type from Table1 where UName='" + TextBox1.Text + "' AND Pwd='" + TextBox2.Text + "'", con);
DataSet ds = new DataSet();
ad.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["Type"].ToString() == "ADMIN")
{
Response.Redirect("Default2.aspx");
}
else
{
Response.Redirect("Default3.aspx");
}
}
else
{
Response.Write("('wrong username and password')");
}
}
}
when i enter admin credential it suppose to redirect to Default2.aspx but it is redirected to Default3.aspx
{
con.Open();
SqlDataAdapter ad = new SqlDataAdapter("select UName,Pwd,Type from Table1 where UName='" + TextBox1.Text + "' AND Pwd='" + TextBox2.Text + "'", con);
DataSet ds = new DataSet();
ad.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
if (ds.Tables[0].Rows[0]["Type"].ToString() == "ADMIN")
{
Response.Redirect("Default2.aspx");
}
else
{
Response.Redirect("Default3.aspx");
}
}
else
{
Response.Write("('wrong username and password')");
}
}
}
when i enter admin credential it suppose to redirect to Default2.aspx but it is redirected to Default3.aspx
Vincent Maverick DuranoPosted Apr 25, 2016, 1:19 AM
If your issue ia resolved please dont forget to close this thread by marking a post which helps you as answer.
Thanks.
jignesh kadvaniPosted Apr 23, 2016, 6:49 AM
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(@"Data Source=.\SQLEXPRESS;Initial Catalog=MySampleDB;Integrated Security=True;Pooling=False");
SqlDataAdapter ad = new SqlDataAdapter("select * from Table1 where UName='" + TextBox1.Text + "' AND Pwd='" + TextBox2.Text + "'", con);
DataSet ds = new DataSet();
ad.Fill(ds);
if (ds.Tables[0].Rows.Count > 0)
{
string role = ds.Tables[0].Rows[0]["Type"].ToString();
if (role.Trim().ToUpper() == "ADMIN")
{
Response.Redirect("Default2.aspx");
}
else if (role.Trim().ToUpper() == "USER")
{
Response.Redirect("Default3.aspx");
}
}
else
{
Response.Write("alert('wrong username and password')");
}
}
}
jignesh kadvaniPosted Apr 22, 2016, 4:31 PM
Vincent Maverick DuranoPosted Apr 22, 2016, 4:27 PM
jignesh kadvaniPosted Apr 22, 2016, 4:25 PM
Vincent Maverick DuranoPosted Apr 22, 2016, 4:19 PM
jignesh kadvaniPosted Apr 22, 2016, 3:58 PM
Vincent Maverick DuranoPosted Apr 22, 2016, 3:48 PM
jignesh kadvaniPosted Apr 22, 2016, 3:43 PM
jignesh kadvaniPosted Apr 22, 2016, 3:40 PM
Vincent Maverick DuranoPosted Apr 22, 2016, 2:23 PM
jignesh kadvaniPosted Apr 22, 2016, 2:12 PM
Vincent Maverick DuranoPosted Apr 22, 2016, 11:13 AM
Pradeep SahooPosted Apr 22, 2016, 10:28 AM
{