登录页面重定向 [英] login page redirection
问题描述
我的登录aspx代码
< asp:TextBox ID = TextBox1 runat = 服务器 >
< asp:TextBox ID = TextBox2 runat = server >
< asp:按钮ID = Button1 runat = server文字= 按钮 OnClick = < span class =code-string> Button1_Click />
< asp:标签ID = Label1 runat = server Text = 标签 >
这是我的登录cs代码
<前lang =c#> 受保护 void Button1_Click( object sender,EventArgs e)
{
int cnt = 0 ;
SqlDataAdapter ad1 = new SqlDataAdapter( @ 从UserReg中选择Id WHERE Name =' + TextBox1.Text + '和密码=' + TextBox2.Text + ',con);
DataTable dt = new DataTable();
ad1.Fill(dt);
cnt = Convert.ToInt32(dt.Rows [ 0 ] [ ID跨度>]);
if (cnt > 0 )
{
Response.Redirect( profile.aspx?id = + cnt); // Response.Redirect(page.aspx?id =+ cnt);
}
else
{
Label1.Text = 用户名或密码无效;
this .Label1.ForeColor = Color.Red;
}
}
登录后如何重定向到用户个人资料页>>?帮助我PLZ以及如何使用[session和cookies]来获取此代码 首先,不要使用这样的内联查询。这导致SQL注入攻击。改为使用参数化查询。
无需使用 DataAdapter
,因为您只读取一个值。你可以使用 DataReader
。
然后调试你的代码,看看发生了什么。您已编码重定向。不是很有效吗?
要在Session中存储值,你可以这样做......
会话[ SomeName] = someValue;
my login aspx code
<asp:TextBox ID="TextBox1" runat="server">
<asp:TextBox ID="TextBox2" runat="server">
<asp:Button ID="Button1" runat="server" Text="Button" OnClick="Button1_Click" />
<asp:Label ID="Label1" runat="server" Text="Label">
it's mine login cs code
protected void Button1_Click(object sender, EventArgs e)
{
int cnt = 0;
SqlDataAdapter ad1 = new SqlDataAdapter(@"select Id from UserReg WHERE Name='" + TextBox1.Text + "' AND Password='" + TextBox2.Text + "'", con);
DataTable dt = new DataTable();
ad1.Fill(dt);
cnt = Convert.ToInt32(dt.Rows[0]["Id"]);
if (cnt > 0)
{
Response.Redirect("profile.aspx?id=" + cnt); //Response.Redirect("page.aspx?id=" + cnt);
}
else
{
Label1.Text = "Invalid username or password";
this.Label1.ForeColor = Color.Red;
}
}
after login how to redirect to the user profile page>>? help me plz and how to use [session and cookies] for this code
First of all, don't use inline queries like this. This leads to SQL Injection attack. Use Parameterized queries instead.
No need to useDataAdapter
, as you are reading only one value. You can useDataReader
.
Then debug your code and see what is happening. You have already coded for redirection. Isn't it working?
To store values in Session, you can do like...
Session["SomeName"] = "someValue";
这篇关于登录页面重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!