我使用的2005,使用的是登录控件,里边有这“下次记住我”,不知道如何使用
解决方案 »
- 导航条点击后变色
- 求asp.net 使用动网论坛的傻瓜文档
- 这个图片要缩放多少比例(等比例)这个图片全部显示在panel中
- 如何让label和image顶端对齐?
- JavaScript脚本如何增加GridView内DropdownList的Item
- 在页面有两个日期格式的字符串,如何将它们转化为日期,并计算时间差??
- 关于弹出对话框的疑问!着急!!!!
- 散 200 分,C# 及 ASP.NET 我是不是选错了?请问 SharpZip 怎么用?
- Gridview 固定表头如何实现?
- Asp.NEt mvc,用jquery+ajax从一个view里获取文本框的值,怎么在另一个View中显示获取的值
- 如何调试输出变量或常量?
- 200分问几个简单问题,帮顶有分!
<head runat="server">
<title>无标题页</title>
</head>
<body>
<form id="form1" runat="server">
<div>
<asp:Panel ID="Panel1" runat="server" Height="50px" Width="125px">
userName:<asp:TextBox ID="TxtName" runat="server"></asp:TextBox>
<br />
<br />
Password:
<asp:TextBox ID="TxtPassword" runat="server"></asp:TextBox>
<br />
<asp:CheckBox ID="CbxRemember" runat="server" Text="记住我" />
<asp:Button ID="BtnSure" runat="server" OnClick="BtnSure_Click" Text="登陆" />
</asp:Panel>
<br />
<br />
<br />
<asp:Button ID="BtnLoginout" runat="server" OnClick="BtnLoginout_Click" Text="注销" />
<br />
<br />
<br />
<br />
<br />
<asp:Label ID="Label1" runat="server" Text="Label"></asp:Label></div>
</form>
</body>
</html>
using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;public partial class Test_TestAutoLogin : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
if (Session["UserName"] == null)
{
if (Request.Cookies.Get("ChinaVT_UserName") != null && Request.Cookies.Get("ChinaVT_UserPssword") != null)
{
Session["UserName"] = Request.Cookies.Get("ChinaVT_UserName").Value;
}
}
if (Session["UserName"] != null)
{
this.Label1.Text = string.Format("<br>{0}使用Cookie已登陆",Session["UserName"].ToString());
Panel1.Visible = false;
BtnLoginout.Visible = true;
}
else
{
this.Label1.Text ="<br>未登陆";
Panel1.Visible = true;
BtnLoginout.Visible = false;
}
}
protected void BtnSure_Click(object sender, EventArgs e)
{
//验证用户名密码成功后写Cookie
if (CbxRemember.Checked)
{
HttpCookie cookieName = new HttpCookie("ChinaVT_UserName", TxtName.Text.Trim());
HttpCookie cookiePassword = new HttpCookie("ChinaVT_UserPssword", TxtPassword.Text.Trim());
cookieName.Expires = System.DateTime.Now.AddDays(7);
cookiePassword.Expires = System.DateTime.Now.AddDays(7);
Response.Cookies.Add(cookieName);
Response.Cookies.Add(cookiePassword); Panel1.Visible = false;
BtnLoginout.Visible = true;
this.Label1.Text = string.Format("<br>{0}使用Cookie已登陆", TxtName.Text.Trim()); }
}
protected void BtnLoginout_Click(object sender, EventArgs e)
{
Response.Cookies.Remove("ChinaVT_UserName");
Response.Cookies.Remove("ChinaVT_UserPssword");
Panel1.Visible = true;
BtnLoginout.Visible = false;
this.Label1.Text = "<br>未登陆";
}
}