使用ASP.NET登录重定向帮助 [英] Login Redirect Help with ASP.NET
本文介绍了使用ASP.NET登录重定向帮助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我的登录页面需要帮助。我有一个登录页面,每次输入用户名和密码时都会变黑。文本框信息被清除。我做错了什么。我想要做的是让一个具有级别编号的成员被重定向到一个欢迎页面,而另一个具有另一个级别编号的用户被定向到他/她的欢迎页面。请帮助我。
I need help with my log in page. I have a login page that every time I enter a username and password it goes black. The textboxes information are cleared out. What did I do wrong. What I am trying to do is to have one member with a level number to be redirected to one welcome page and the other user with another level number be directed to his/her welcome page. Please help me.
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.Configuration;
using System.Data;
public partial class Login : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
}
protected void Button1_Click(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
con.Open();
if (true)
{
string cmdStr3 = "select Password, accessLevel from TableSecurity where EmailAddress= '" + TextBoxEA.Text + "'";
SqlCommand level = new SqlCommand(cmdStr3, con);
SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(reader);
foreach (DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1[0].ToString());
if (returnedLevel == 1)
{
Response.Redirect("~/Secure.aspx");
}
else if (returnedLevel == 2)
{
Response.Redirect("~/WelcomeIALO.aspx");
}
}
}
con.Close();
}
}
推荐答案
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.Configuration;
using System.Data;
public partial class _Default : System.Web.UI.Page
{
protected void Button1_Click1(object sender, EventArgs e)
{
SqlConnection con = new SqlConnection(ConfigurationManager.ConnectionStrings["PassConnectionString"].ConnectionString);
con.Open();
if (true)
{
SqlCommand level = new SqlCommand("select accessLevel, Password from TableSecurity where EmailAddress = @Email AND Password = @password", con);
level.Parameters.Add(new SqlParameter("Email", TextBoxEA.Text));
level.Parameters.Add(new SqlParameter("password", TextBoxPW.Text));
SqlDataReader reader = level.ExecuteReader();
DataTable dt1 = new DataTable();
dt1.Load(reader);
foreach (DataRow dr1 in dt1.Rows)
{
int returnedLevel = Convert.ToInt32(dr1[0].ToString());
if (returnedLevel == 1)
{
Response.Redirect("~/Default2.aspx");
}
else if (returnedLevel == 2)
{
Response.Redirect("~/Default2.aspx");
}
}
}
con.Close();
}
}
这篇关于使用ASP.NET登录重定向帮助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文