asp.net中的登录页面 [英] login page in asp.net

查看:83
本文介绍了asp.net中的登录页面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,



当用户使用有效的用户名和密码登录时,我需要一个登录页面,它将重定向到另一个显示welcome的页面:用户名

谢谢

Hi all,



I need a login page when the user login with valid user name and password it will redirect to another page showing welcome :username

Thanks

推荐答案

< pre lang ="c#"> if(!Page.IsPostBack)
{
//检查用户是直接访问此页面还是来自登录页面.
如果(Session ["user"] == null)
{
//用户直接访问,因此不允许查看此页面内容
Response.Redirect("Default.aspx");
}
其他
{
Label1.Text =欢迎" +会话[用户"] .ToString();
}
}




受保护的void Button1_Click(对象发送者,EventArgs e)
{
sqlcon.Open();
sqlcmd = new SqlCommand(从usr_detail中选择*,其中uname ="''+ TextBox1.Text +''和pwd ="''+ TextBox2.Text +'',sqlcon);
dt.Clear();
da =新的SqlDataAdapter(sqlcmd);
da.Fill(dt);
如果(dt.Rows.Count> 0)
{
会话[用户"] = TextBox1.Text;
Response.Redirect("Default2.aspx");
}
其他{
TextBox1.Text =";
TextBox2.Text =";
Label1.Text =无效的登录详细信息!";
}
}</pre>
<pre lang="c#">if (!Page.IsPostBack)
{
//Check whether user directly access this page or come from Login page.
if (Session["user"] == null)
{
//user access directly so not permit to view this page content
Response.Redirect("Default.aspx");
}
else
{
Label1.Text = "Welcome " + Session["user"].ToString();
}
}




protected void Button1_Click(object sender, EventArgs e)
{
sqlcon.Open();
sqlcmd = new SqlCommand("select * from usr_detail where uname=''" + TextBox1.Text + "'' and pwd=''" + TextBox2.Text + "''",sqlcon);
dt.Clear();
da = new SqlDataAdapter(sqlcmd);
da.Fill(dt);
if (dt.Rows.Count > 0)
{
Session["user"] = TextBox1.Text;
Response.Redirect("Default2.aspx");
}
else {
TextBox1.Text = "";
TextBox2.Text = "";
Label1.Text = "Invalid Login Details!";
}
}</pre>


您好,首先创建必要的文本框和按钮.
然后使用sqlconnection连接到数据库.
使用用户名和密码创建登录表的数据集.
如果ds.hasrows选中了复选框中的值.
如果用户输入正确,则页面将被重定向,并且
使用response.write写入textbox(用于用户名)的值.

通过尝试来做到.

祝你好运....
Hello, first of all you create necessary textboxs and button.
then connect to the database using sqlconnection.
create dataset of login table with username and password.
if ds.hasrows the check for values in checkboxes.
if correct user input then page will be redirect and
write the value of textbox(which used for username) using response.write.

do it by trying..

best of luck....


^ ]


这篇关于asp.net中的登录页面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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