Tech
Forums
Jobs
Books
Events
Interviews
Live
More
Learn
Training
Career
Members
Videos
News
Blogs
Login
Sign Up
Ask Question
14
Reply
how to redirect to perticular page using auithenication
jignesh kadvani
Apr 22 2016 8:00 AM
550
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");
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("</script/>('wrong username and password')</script/>");
}
}
}
when i enter admin credential it suppose to redirect to Default2.aspx but it is redirected to Default3.aspx
Reply
Upload Source Code
Select only zip and rar file.
Post
Reset
Answers (
14
)
Demo of CRUD Operation Using SignalR in Visual Studio 2010
How to bind the data in gridview by using n tier