我正在尝试制作登录屏幕,它将不同的用户重定向到不同的屏幕。我有一个数据库表。字段是。sql表设计
username Varchar(50)
password Varchar(50)
Designation Text
IsAdmin bit
现在我有两个文本字段,分别带有一个登录按钮
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.Configuration;
using System.Data.SqlClient;
public partial class _Default : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Login1_Authenticate(object sender, AuthenticateEventArgs e)
{
string username = Login1.UserName;
string password = Login1.Password;
string CurrentName;
string s;
s = WebConfigurationManager.ConnectionStrings["ovmsConnectionString"].ConnectionString;
SqlConnection con = new SqlConnection(s);
con.Open();
string sqlUserName;
//FOR NORMAL USERS
if(username != null)
{
sqlUserName = "SELECT username,password FROM tblLogin WHERE username ='" + username + "' AND password ='" + password + "'";
SqlCommand cmd = new SqlCommand(sqlUserName, con);
CurrentName = (string)cmd.ExecuteScalar();
if (CurrentName != null)
{
Session["UserAuthentication"] = username;
Session.Timeout = 1;
Response.Redirect("start.aspx");
}
else
{
Session["UserAuthentication"] = "";
}
}
}
}
我想在登录后向驱动程序显示一个不同的页面,并向管理员显示一个不同的页面(管理面板)。
我有两个查询我只想通过一个表单进行管理面板登录、用户登录屏幕和驱动程序登录屏幕。
like :
Query for driver
SELECT username, password, Designation
FROM dbo.tblLogin
WHERE (Designation LIKE 'driver')
and for Admin Login
SELECT username, password, IsAdmin
FROM dbo.tblLogin
WHERE (IsAdmin = 1)