易截截图软件、单文件、免安装、纯绿色、仅160KB

ASP.NET中Cookie的操作

在学习过程中需要用到Cookie文件,在网上找了些相关的知识,学习了一部分,现记录如下:
(1)
HttpCookie myHttpCookie = new HttpCookie("MyWebSite");
DateTime myDateTime = System.DateTime.Now;
TimeSpan myTimeSpan = new TimeSpan();
if (rbHour.Checked == true)
{
    myTimeSpan = new TimeSpan(0, 1, 0, 0, 0);
    myTime = 0;
}
if (rbDay.Checked == true)
{
    myTimeSpan = new TimeSpan(1, 0, 0, 0, 0);
    myTime = 1;
}
myHttpCookie.Expires = myDateTime.Add(myTimeSpan);
myHttpCookie.Values.Add("UserName", Server.HtmlEncode(txtUserName.Text.Trim().ToString()));
myHttpCookie.Values.Add("Sex", Server.HtmlEncode(mySex));
myHttpCookie.Values.Add("SelectTime", Server.HtmlEncode(myTime.ToString()));
Response.AppendCookie(myHttpCookie);
这段代码的作用是创建一个名为MyWebSite的Cookie文件,里面有三项,分别是UserName(用户名)、Sex(性别)和SelectTime(Cookie的过期时间)。
(2)
if (Request.Cookies["MyWebSite"] != null)
{
    myUserName = Request.Cookies["MyWebSite"]["UserName"].ToString();
    mySex = Request.Cookies["MyWebSite"]["Sex"].ToString();
    myTime = Request.Cookies["MyWebSite"]["SelectTime"].ToString();
}
if (myUserName != null && mySex != null)
{
    HttpCookie myHttpCookie = new HttpCookie("MyWebSite");
    if (myHttpCookie != null)
    {
        myHttpCookie.Values["UserName"] = myUserName.ToString();
        myHttpCookie.Values["Sex"] = mySex.ToString();
        myHttpCookie.Values["SelectTime"] = myTime.ToString();
        DateTime myDateTime=System.DateTime.Now;
        if (myTime.ToString() == "0")
        {
          &nb


相关文档:

asp.net将页面中gridview中的数据导入excel表中

using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using System.IO;
namespace ......

ASP.NET页面跳转的三大方法详解

ASP.NET页面跳转有什么方法呢?,现在给大家介绍三种方法,他们的区别是什么呢?让我们开始吧: ASP.NET页面跳转1、response.redirect 这个跳转页面的方法跳转的速度不快,因为它要走2个来回(2次postback),但他可以跳转到任何页面,没有站点页面限制(即可以由雅虎跳到新浪),同时不能跳过登录保护。但速度慢是其最大缺陷!r ......

学习asp.net比较完整的流程[转]

如果你已经有较多的面向对象开发经验,跳过以下这两步:
  第一步 掌握一门.NET面向对象语言,C#或VB.NET 我强烈反对在没系统学过一门面向对象(OO)语言的前提下去学ASP.NET。 ASP.NET是一个全面向对象的技术,不懂OO,那绝对学不下去!
  第二步 对.NET Framework类库有一定的了解 可以通过开发Windows Form应用程 ......

asp.net(C#)字符串加密

asp.net(C#)字符串加密
2010-03-12 09:59
using System;   
using System.Collections.Generic;   
using System.Text;   
using System.Security.Cryptography;//Cryptography密码术   
namespace DAL   
{   
......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号