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

Asp.net 中 Cookie的使用方法

方法1:
比如建立一个名为cnlive,值为"123"的cookie
HttpCookie cookie = new HttpCookie["cnlive"];
cookie.Value = "123";
Response.AppendCookie(cookie);
取刚才写入的Cookie值:
HttpCookie cookie = Request.Cookies["cnlive"];
cookieValue = cookie.Value;
在一个Cookie中储存多个信息:
HttpCookie cookie = new HttpCookie("cnlive");
cookie.Values.Add("weburl",http://www.cnlive.net);
cookie.Values.Add("author","honfei");
cookie.Values.Add("sitename","网友与媒体");
Response.AppendCookie(cookie);
读取:
HttpCookie cookie = Request.Cookies["cnlive"];
value1 = cookies.Values["weburl"];
value2 = cookies.Values["author"];
.............
方法二:
Response.Cookies["UserID"].Value = "123";//将用户ID写入Cookie
Response.Cookies["UserID"].Expires = DateTime.Now.AddDays(1);
读取方法:
Request.Cookies["UserID"].Value;
写cookie
HttpCookie cookie = new HttpCookie("Info");//定义cookie对象以及名为Info的项
DateTime dt = DateTime.Now;//定义时间对象
TimeSpan ts=new TimeSpan(1,0,0,0);//cookie有效作用时间,具体查msdn
cookie.EXPires = dt.Add(ts);//添加作用时间
cookie.Values.Add("user","cxbkkk");//增加属性
cookie.Values.Add("userid","1203");
Response.AppendCookie(cookie);//确定写入cookie中 读取cookie
if(Request.Cookies["Info"]!=null)
{
string temp=Convert.ToString(Request.Cookies["Info"].Values["user"])+" "+Convert.ToString(Request.Cookies["Info"].Values["userid"]);
//读全部就用Request.Cookies["Info"].Value)
if(temp=="")
{
Response.Write("空");
}
else
Response.Write(temp);
}
else
{
Response.Write("error");
} 修改cookie
Response.Cookies["Info"]["user"] = "2";
Response.Cookies["Info"].Expires = DateTime.Now.AddDays(1);
// 删除cookie下的属性
HttpCookie acookie=Request.Cookies["Info"];
acookie.Values.Remove("userid");
acookie.Expires = DateTime.Now.AddDays(1);
Response.Cookies.Add(acookie); 删除所有cookie,就是设置过期时间为现在就行了
int limit=Request.Cookies.Count - 1;
for(int i=0;i<limit;i++)
{
acookie = Request.Cookies(i)
acookie.Expires = DateTime.N


相关文档:

关于ASP.NET控件在编译时找不到的解决方案

     本人开发ASP.NET已有两年多了。谈起ASP.NET真是让我欢喜让我忧。昨天又出现了那个奇怪的问题,就是在页面完全写好后,重新生成时报:XXX(页面名)不包含(XXX)的定义。在CS文件下是可以用 this.xxx 写出来的,页面上也没问题。在解决方案中重新生成页又可以,重新生成网站就会报这个错误。将this.XXX ......

Asp.Net使用正则表达式解析中英文混排内容

给出一个字符串,如“中国China我爱你I love you”,程序可以实现中英文的区别;
识别结果如下:共四个元素
中国
China
我爱你
I love you
 
 
 string ptn = "[\u4e00-\u9fa5]+|[a-zA-Z\\s]+";
System.Text.RegularExpressions.Regex reg = new System.Text.RegularExpressions.Regex(ptn);
s ......

用asp.net生成html静态页的两种方法~~~

第一种方法是对一个aspx页面生成html文件,先对服务器发送请求aspx页面,取服务器返回的html流,写到一个html文件里,aspx页面显示的是什么,生成的html页面就是什么
1、asp方法:
sub createHTML
  dim xmlhttp,strhtml,objAdoStream,i,myurl
  set xmlhttp=server.CreateObject("Microsoft.XMLHTTP")
&nb ......

ASP.NET 数据绑定常用代码

用DataBinder.eval 绑定数据不必关心数据来源(Dataread或dataset)也不必关心数据的类型,eval会把这个数据对象转换为一个字符串。是底层绑定做了很多工作,使用了反射性能。正因为使用方便了,但却影响了数据性能。当与dataset绑定时,DataItem其实是一个DataRowView(如果绑定的是一个数据读取器(dataread)它就是一个Idat ......

asp.net 程序动态添加gridview

前台:
<html xmlns="http://www.w3.org/1999/xhtml">
<head id="Head1" runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
   
   
     ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号