登录页:
前台:
<div>
用户:<asp:TextBox ID="txtUserName" runat="server"></asp:TextBox><br />
密码:<asp:TextBox ID="txtPwd" runat="server"></asp:TextBox><br />
<asp:Button ID="Button1" runat="server" Text="登录" οnclick="Button1_Click" />
</div>
后台:
protected void Button1_Click(object sender, EventArgs e)
{
if (txtUserName.Text=="admin"&&txtPwd.Text=="888888")
{
Session["username"] = txtUserName.Text;
Response.Redirect("WebBlock.aspx");
}
}
跳转的页子(ps:将注册信息写入到文本中):
<div>
<asp:TextBox ID="TextBox1" runat="server" Height="382px" TextMode="MultiLine"
Width="478px"></asp:TextBox>
<asp:Button ID="Button1" runat="server" Text="保存" οnclick="Button1_Click" />
</div>
后台:
protected void Button1_Click(object sender, EventArgs e)
{
if (Session["username"] != null)
{
FileStream stream = File.Open(@"d:\1.txt", FileMode.OpenOrCreate, FileAccess.Write);
StreamWriter writer = new StreamWriter(stream);
writer.Write(TextBox1.Text);
writer.Dispose();
stream.Dispose();
}
else
{
Response.Redirect("Error.aspx");
}
}
Web.config中设置时间:
<system.web>
<compilation debug="true" targetFramework="4.0" />
<sessionState timeout="1"/>
</system.web>
查实后跳转的页子Error页:
<div>
登录超时,请重新登录。
</div>