Login.aspx

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="Login.aspx.cs" Inherits="CZBK.ItcastProject.WebApp._2015_5_31.Login" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<form id="form1" runat="server">
<div>
用户名:<input type="text" name="txtName" value="<%=LoginUserName %>" /><br />
密码:<input type="password" name="txtPwd" value="<%=LoginPwd %>" /><br />
<input type="submit" value="登录" />
</div>
</form>
</body>
</html>

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 CZBK.ItcastProject.WebApp._2015_5_31
{
public partial class Login : System.Web.UI.Page
{
public string LoginUserName { get; set; }
public string LoginPwd { get; set; }
protected void Page_Load(object sender, EventArgs e)
{
if (IsPostBack)
{
string userName = Request.Form["txtName"];
string userPwd = Request.Form["txtPwd"];
//写到Cookie中
Response.Cookies["userName"].Value = Server.UrlEncode(userName);
Response.Cookies["userPwd"].Value = Server.UrlEncode(userPwd);
Response.Cookies["userName"].Expires = DateTime.Now.AddDays();
Response.Cookies["userPwd"].Expires = DateTime.Now.AddDays();
//读取cookie.
if (Request.Cookies["userName"] != null)
{
string name = Server.UrlDecode(Request.Cookies["userName"].Value);
LoginUserName = name;
}
if (Request.Cookies["userPwd"] != null)
{
string pwd = Server.UrlDecode(Request.Cookies["userPwd"].Value);
LoginPwd = pwd;
}
}
else
{
//读取cookie.
if (Request.Cookies["userName"]!=null)
{
string name = Server.UrlDecode(Request.Cookies["userName"].Value);
LoginUserName = name;
}
if (Request.Cookies["userPwd"] != null)
{
string pwd = Server.UrlDecode(Request.Cookies["userPwd"].Value);
LoginPwd = pwd;
}
}
}
}
}

最新文章

  1. Linux杀死进程,查看进程
  2. vim安装中文帮助手册
  3. AOS – 另外一个独特的页面滚动动画库(CSS3)
  4. AJAX第二发
  5. php web 信息采集
  6. Hive与数据库的异同
  7. UVa 10561 - Treblecross
  8. Openjudge计算概论-计算矩阵边缘元素之和
  9. 为网站添加网址图标favicon.ico
  10. apache2.2 + tomcat6 整合以及集群配置整理
  11. configure.ac:20: error: Autoconf version 2.65 or higher is required
  12. therefore/so/hence/then/accordingly/Thus
  13. Oracle日期查询:季度、月份、星期等时间信息
  14. [转载] epoll详解
  15. Oracle知识梳理(三)操作篇:SQL基础操作汇总
  16. #Java学习之路——基础阶段(第四篇)
  17. Android BroadcastReceiver解析
  18. Codeforces 837E Vasya&#39;s Function - 数论
  19. 邮箱登录form表单样例
  20. mac chrome 驱动配置

热门文章

  1. vi/vim 三种模式的操作
  2. Strusts2
  3. FPGA开发随笔汇总
  4. js读取txt文件
  5. HTML5元素标记释义
  6. Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: &#39;on_delete&#39;
  7. Xcode中SVN不能提交.a文件的解决方法
  8. Dubbo 源码分析 - 服务调用过程
  9. JavaScript工作体系中不可或缺的函数
  10. Java工程师如何在1个月内做好面试准备?