TECHNOLOGIES
ANSWERS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
jignesh kadvani
0
78
0
how to redirect to perticular page using auithenication
Apr 22 2016 8:00 AM
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
Answers (
14
)
Demo of CRUD Operation Using SignalR in Visual Studio 2010
How to bind the data in gridview by using n tier