Login.aspx.cs
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
namespace 类库名.WebApp
{
public partial class Login : System.Web.UI.Page
{
public string LoginUserName { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack) //如果是Post请求(点击提交)
{
string userName = Request.Form["txtName"];
//写到Cookie中.
Response.Cookies["userName"].Value = Server.UrlEncode(userName);
Response.Cookies["userName"].Expires = DateTime.Now.AddDays(7);
}
else //否则是Get请求,回显用户名
{
//读Cookie。
if (Request.Cookies["userName"] != null)