Cookie登录保存
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登录保存的更多相关文章
- Android WebView保存Cookie登录
因项目需要,需要在App中嵌入网页,使用Nativie方式登录,然后将cookie保存到WebView中,实现免登录功能.同步Cookie到WebView的方法网上有大量的参考资料,也可以参考下面的代 ...
- JMeter学习-018-JMeter 配置元件之-HTTP信息头管理器-实现 Cookie 登录
之前写过一篇通过[HTTP Cookie管理器]实现登录态操作的文章,使用时需要配置每个键值对(如下图所示),相对来讲配置比较繁琐.其实,我们也可通过在[HTTP信息头管理器]添加 Cookie 信息 ...
- JMeter学习-012-JMeter 配置元件之-HTTP Cookie管理器-实现 Cookie 登录
前文我们讲过了若何获取登录后的 Cookie 信息,不知如何获取登录 Cookie 的朋友,敬请参阅我之前写的博文:Fiddler-005-获取 Cookie 信息.参阅上篇文章,获取到 Cookie ...
- jQuery cookie插件保存用户登陆信息
通过jquery cookie插件保存用户登录信息. 代码: <html> <head> <title>cookies.html</title> ...
- 简单的Cookie登录
登录页前台代码 <form id="form1" action ="" method="post"> <input typ ...
- python3爬虫 - cookie登录实战
http://blog.csdn.net/pipisorry/article/details/47948065 实战1:使用cookie登录哈工大ACM网站 获取网站登录地址 http://acm.h ...
- 人人网(cookie登录)
有时候,我们在爬取一些网页之前必需要登录该网站,比如说我想爬取我的人人网主页内容. 1.打开:www.renren.com 2.输入用户名和密码,登录网站18679030315 3.个人首页,如下图: ...
- python爬虫-使用cookie登录
前言: 什么是cookie? Cookie,指某些网站为了辨别用户身份.进行session跟踪而储存在用户本地终端上的数据(通常经过加密). 比如说有些网站需要登录后才能访问某个页面,在登录之前,你想 ...
- python selenium cookie 登录
概要: 1.正常登录,使用selenium获取cookie: 2.保存cookie: 3.使用cookie登录. 4.python--2.7,selenium--3.4.1 步骤1 正常登录,使用se ...
随机推荐
- MySql添加远程超级管理员用户
可以通过发出GRANT语句增加新用户:首先在数据库本机上用ROOT用户登录上MySql,然后运行命令: mysql>GRANT ALL PRIVILEGES ON *.* TO admin'@' ...
- C/C++字符串相关知识使用整理
C++字符串处理有最原始的char以及string两种方式,这里对其常用的功能进行总结. #include <string>using namespace std; ]; string s ...
- Linux---一级/二级目录以及位置目录名/指令
home目录:普通用户登录进来以后的初始位置(会在home目录下创建一个登录名相同的目录例如 / home / 用户名),如果是超级用户则就是 在根目录 /下的 root目录(也就是 /root) ...
- C语言的转义字符
原文地址:http://blog.163.com/sunshine_linting/blog/static/44893323201181325818165/ 在字符集中,有一类字符具有这样的特性:当从 ...
- 安装完Ubuntu后通过shell脚本一键安装软件
安装完Ubuntu后通过shell脚本一键安装软件 以下代码中#是单行注释 :<<! ! 是多行注释. 运行的时候需要把多行注释去掉. 比如把以下代码保存为install.sh, 那么在终 ...
- css伪元素 ::after ::before
我遇到的问题: div盒子标签设置了伪元素 ::after ::before 并给这俩content内容设置了空属性,添加了背景图,发现这两个伪元素没有宽度和高度. 解决方法 给设置伪元素的盒子的 ...
- JVM垃圾收集器与内存分配策略(一)
在前面的Java自动内存管理机制(上)和Java自动内存管理机制(下)中介绍了关于JVM的一些基础知识,包括运行时数据区域划分和一些简单的参数配置,而其中也谈到了GC,但是没有深入了解,所以这里开始简 ...
- {黑掉这个盒子} \\ FluxCapacitor Write-Up
源标题:{Hack the Box} \ FluxCapacitor Write-Up 标签(空格分隔): CTF 好孩子们.今天我们将学习耐心和情绪管理的优点.并且也许有一些关于绕过WEB应用防 ...
- IM群聊消息的已读回执功能该怎么实现?
本文引用了架构师之路公众号作者沈剑的文章,内容有改动,感谢原作者. 1.前言 我们平时在使用即时通讯应用时候,每当发出一条聊天消息,都希望对方尽快看到,并尽快回复,但对方到底有没有真的看到?我却并不知 ...
- 每天学点SpringCloud(十三):SpringCloud-Stream整合RabbitMQ
我们知道,当微服务越来越来多的时候,仅仅是feign的http调用方式已经满足不了我们的使用场景了.这个时候系统就需要接入消息中间件了.相比较于传统的Spring项目.SpringBoot项目使用消息 ...