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;
}
}
}
}
}

Cookie登录保存的更多相关文章

  1. Android WebView保存Cookie登录

    因项目需要,需要在App中嵌入网页,使用Nativie方式登录,然后将cookie保存到WebView中,实现免登录功能.同步Cookie到WebView的方法网上有大量的参考资料,也可以参考下面的代 ...

  2. JMeter学习-018-JMeter 配置元件之-HTTP信息头管理器-实现 Cookie 登录

    之前写过一篇通过[HTTP Cookie管理器]实现登录态操作的文章,使用时需要配置每个键值对(如下图所示),相对来讲配置比较繁琐.其实,我们也可通过在[HTTP信息头管理器]添加 Cookie 信息 ...

  3. JMeter学习-012-JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录

    前文我们讲过了若何获取登录后的 Cookie 信息,不知如何获取登录 Cookie 的朋友,敬请参阅我之前写的博文:Fiddler-005-获取 Cookie 信息.参阅上篇文章,获取到 Cookie ...

  4. jQuery cookie插件保存用户登陆信息

    通过jquery cookie插件保存用户登录信息. 代码: <html>  <head>  <title>cookies.html</title>  ...

  5. 简单的Cookie登录

    登录页前台代码 <form id="form1" action ="" method="post"> <input typ ...

  6. python3爬虫 - cookie登录实战

    http://blog.csdn.net/pipisorry/article/details/47948065 实战1:使用cookie登录哈工大ACM网站 获取网站登录地址 http://acm.h ...

  7. 人人网(cookie登录)

    有时候,我们在爬取一些网页之前必需要登录该网站,比如说我想爬取我的人人网主页内容. 1.打开:www.renren.com 2.输入用户名和密码,登录网站18679030315 3.个人首页,如下图: ...

  8. python爬虫-使用cookie登录

    前言: 什么是cookie? Cookie,指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密). 比如说有些网站需要登录后才能访问某个页面,在登录之前,你想 ...

  9. python selenium cookie 登录

    概要: 1.正常登录,使用selenium获取cookie: 2.保存cookie: 3.使用cookie登录. 4.python--2.7,selenium--3.4.1 步骤1 正常登录,使用se ...

随机推荐

  1. Java学习笔记day_01

    Java学习笔记(复习整理) 虽然不知道该怎么写,但是不起步就永远不知道该怎么做..刚开始可能会写的很差劲,但会一点一点变好的. 本笔记是以我按照传智播客的视频和Java核心思想来学习,前面的基础部分 ...

  2. python Flask框架mysql数据库配置

    我是一个没有笔记习惯的低级程序员,但是我还是喜欢编程,从小学就开始跟着玩电脑,对抓鸡,ddos,跳板刷钻开始了自己的IT 旅程,之后学习了各种语言,但是可惜都不没有达到精通,都是略懂一二,现在想把Py ...

  3. 《Linux就该这么学》第十八天课程

    1.使用MariaDB数据库管理系统 今天没什么笔记,就不发了.想深入学习的可以前往原创地址:https://www.linuxprobe.com/chapter-18.html 图18-1 Mari ...

  4. git操作之git clean删除一些没有git add的文件

    删除 一些 没有 git add 的 文件: git clean 参数 -n 显示 将要 删除的 文件 和  目录 -f 删除 文件,-df 删除 文件 和 目录

  5. 解决更新ssh后在/etc/init.d下无sshd的问题

    1.将远程服务器的/etc/init.d/ssd  文件拷贝到本地 scp /etc/init.d/ssh  root@IP地址:/etc/init.d 2.vi /etc/init.d/sshd 3 ...

  6. appium手机键盘实现方法

    首先引入appium的webdriver from appium import webdriver 方法1 AppiumDriver实现了在上述功能,代码如下(java版本) driver.sendK ...

  7. one-to-one 一对一映射关系(转 wq群)

    2.配置对应的xml配置文件 person的配置文件 idCard的配置文件 idCard的配置文件  3.测试 运行测试程序后,控制台输出两条语句

  8. _ZNote_Window_技巧_删除开机启动项

    win + R 输入msconfig 可以打开

  9. C#使用Dotfuscator混淆代码的加密方法

    C#编写的代码如果不进行一定程度的混淆和加密,那么是非常容易被反编译进行破解的,特别是对于一些商业用途的C#软件来说,因为盯着的人多,更是极易被攻破.使用VS自带的Dotfuscator可以实现混淆代 ...

  10. java导出2007版word(docx格式)freemarker + xml 实现

    http://blog.csdn.net/yigehui12/article/details/52840121 Freemarker+xml生成docx 原理概述:word从2003版就支持xml格式 ...