登录页面并根据用户类型进行检查 [英] Login page and check as per usertype

查看:65
本文介绍了登录页面并根据用户类型进行检查的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建NewUser表和登录页面.

我有登录"页面,在该登录页面中1)UserName(txtbox1),2)Password(txtbox2),3)DropDownList(Admin/Executive)和登录"按钮中的UserType.

当我单击Login Btn时,它将按照数据库(NewUser Tbl)检查用户名,pass,usertyper(如果我选择"Admin"),并在Admin(Folder)---> Home.aspx(Its Belog)中重定向页面到母版页"),如果我选择执行"检查用户名和密码,并将页面重定向到Executive(文件夹)---> Home.aspx,则执行类似,否则会给出无效的密码和用户名.根据asp.net 4.0的plz解决方案

I am create NewUser Table, and Login Page.

I have Login page, in that login page 1)UserName(txtbox1),2)Password(txtbox2),3)UserType In DropDownList(Admin/Executive) & Login Button.

When I click Login Btn , it will check username,pass,usertyper( if I chooes "Admin")so as per DB (NewUser Tbl) and redirect the page in Admin(Folder)--->Home.aspx(Its Belog to Master Page), similar for Execute if i chooes "Executive" check username & pass and page redirect to Executive(Folder)--->Home.aspx other wise give invalid pass & username. plz solustion as per asp.net 4.0

推荐答案

满足您的要求,我给出了最简单的解决方案,

我想你有newusertbl与用户名,密码和用户类型列.列用户类型的值应为"Admin"或"Executive".此外,您的下拉列表的值包括管理员"和执行".

在登录"按钮中,单击"evt".使用以下代码:


受保护的void LoginBtn_Click(对象发送者,EventArgs e)
{
字符串qry = string.Empty;
qry =从NewUserTbl中选择userType,其中用户名=""+ TextBox1.Text.Trim()+"''和密码=" + TextBox2.Text.Trim()+''";
SqlConnection testDBConnection =新的SqlConnection(数据源= .;初始目录= TestDb;集成安全性= True");
testDBConnection.Open();
SqlCommand cmd =新的SqlCommand(qry,testDBConnection);
字符串userType = Convert.ToString(cmd.ExecuteScalar());
如果(string.IsNullOrEmpty(userType))
{
Response.Write(无效的用户名或密码");
}
否则,如果(RoleDDL.SelectedItem.Text =="Admin" && userType =="Admin")
{
Response.Redirect("Admin \\ AdminHome.aspx");
}
否则,如果(RoleDDL.SelectedItem.Text =="Executive" && userType =="Executive")
{
Response.Redirect("Executive \\ ExecutiveHome.aspx");
}
}


在这里,
TextBox1是用户名TextBox,
TextBox2是密码TextBox,
RoleDDL是Dropdownlist.
for your requirements, i''m giving the simplest solution,

i guess u have newusertbl with columns username, password and usertype. The value of the column usertype should be either ''Admin'' or ''Executive''. Also, ur dropdownlist has the values ''Admin'' and ''Executive''.

in Login button click evt. use the following code:


protected void LoginBtn_Click(object sender, EventArgs e)
{
string qry = string.Empty;
qry = "select userType from NewUserTbl where username=''" + TextBox1.Text.Trim() + "'' and password=''" + TextBox2.Text.Trim() + "''";
SqlConnection testDBConnection = new SqlConnection("Data Source=.;Initial Catalog=TestDb;Integrated Security=True");
testDBConnection.Open();
SqlCommand cmd = new SqlCommand(qry, testDBConnection);
string userType = Convert.ToString(cmd.ExecuteScalar());
if (string.IsNullOrEmpty(userType))
{
Response.Write("Invalid username or Password");
}
else if (RoleDDL.SelectedItem.Text == "Admin" && userType == "Admin")
{
Response.Redirect("Admin\\AdminHome.aspx");
}
else if (RoleDDL.SelectedItem.Text == "Executive" && userType == "Executive")
{
Response.Redirect("Executive\\ExecutiveHome.aspx");
}
}


Here,
TextBox1 is username TextBox,
TextBox2 is Password TextBox,
RoleDDL is the Dropdownlist.


那您的问题是什么?您面对问题时会在哪里解释您的特定问题?
then what is your question ? where u facing problem pls explain your particular problem ?


这篇关于登录页面并根据用户类型进行检查的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆