Cookie登录保存
2024-10-14 16:10:42
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;
}
}
}
}
}
最新文章
- Linux杀死进程,查看进程
- vim安装中文帮助手册
- AOS – 另外一个独特的页面滚动动画库(CSS3)
- AJAX第二发
- php web 信息采集
- Hive与数据库的异同
- UVa 10561 - Treblecross
- Openjudge计算概论-计算矩阵边缘元素之和
- 为网站添加网址图标favicon.ico
- apache2.2 + tomcat6 整合以及集群配置整理
- configure.ac:20: error: Autoconf version 2.65 or higher is required
- therefore/so/hence/then/accordingly/Thus
- Oracle日期查询:季度、月份、星期等时间信息
- [转载] epoll详解
- Oracle知识梳理(三)操作篇:SQL基础操作汇总
- #Java学习之路——基础阶段(第四篇)
- Android BroadcastReceiver解析
- Codeforces 837E Vasya&#39;s Function - 数论
- 邮箱登录form表单样例
- mac chrome 驱动配置
热门文章
- vi/vim 三种模式的操作
- Strusts2
- FPGA开发随笔汇总
- js读取txt文件
- HTML5元素标记释义
- Django关联数据库时报错TypeError: __init__() missing 1 required positional argument: &#39;on_delete&#39;
- Xcode中SVN不能提交.a文件的解决方法
- Dubbo 源码分析 - 服务调用过程
- JavaScript工作体系中不可或缺的函数
- Java工程师如何在1个月内做好面试准备?