| 类别: |
CSharp.Net, function
|
| 标签: |
c#, Cookie, AddCookie, Cookies
|
| 摘要: |
添加 Cookie
|
| 正文: |
- <%@ Control Language="C#" AutoEventWireup="True" className="NavBar" %>
- <script runat="server">
- void Page_Load(Object s, EventArgs e)
- {
- //AddCookie("test1", "test1Value2", 10);
-
- Response.Write(
- ReadCookie("test1")
- );
- } // end Page_Load
-
- private void AddCookie(string key, string value, int minutes)
- {
- HttpCookie hc = new HttpCookie(key, value);
- DateTime dt = DateTime.Now;
- TimeSpan ts = new TimeSpan(0, 0, minutes, 0);
- hc.Expires = dt.Add(ts);
- Response.Cookies.Add(hc);
- }
-
- public string ReadCookie(string key)
- {
- if(HttpContext.Current.Request.Cookies[key]==null) return "";
- return HttpContext.Current.Request.Cookies[key].Value+"";
- }
- </script>
|
| 文章相关信息: |
|
| 主题: |
c# 添加 Cookie 函数 AddCookie
|
| 发表者: |
shawl.qiu
|
| 电子邮件: |
shawl.qiu@gmail.com
|
| QQ: |
908202921
|
| MSN: |
btbtd@msn.com
|
| Homepage: |
http://www.btbtd.org/
|
| Blog: |
http://blog.csdn.net/btbtd/
|
| 发表日期: |
2007-3-4 21:50:25
|
| 更新日期: |
2007-3-4 21:50:25
|
| 来源引用: |
shawl.qiu CSharp DotNet 个人资料管理系统
|
| 引用本页: |
http://gi.2288.org/mod/code/display/Default.aspx?aid=317
|