首页 新闻 会员 周边

C#如何ie cookies和缓存

0
[已关闭问题] 关闭于 2009-11-30 08:51

今天google和百度了半天都找不到C#如何ie cookies和缓存(像360那样).大部分都是复制别人的代码,没有看过能否运行,希望高手能解决.

asp.net.asp.net的主页 asp.net.asp.net | 初学一级 | 园豆:10
提问于:2009-11-16 13:54
< >
分享
所有回答(2)
0

 保存和讀取是不一樣的。

COOKIES裡面的特殊字符也要做處理

Dim vType As String
        vType = Request("vtype")
        Dim ContentStr As String
        If vType = "SaveCookies" Then '保存COOKIES
            ContentStr = Request("con")
            If Response.Cookies("chatbox") Is Nothing Then
                Dim cookie As New HttpCookie("chatbox")
                Dim dt As DateTime
                dt = Now()
                Dim ts As New TimeSpan(0, 1, 0)
                cookie.Expires = dt.Add(ts)
                cookie.Values("con") = ContentStr
                Response.Cookies.Add(cookie)
            Else
                Dim cookie As HttpCookie = Response.Cookies("chatbox")
                ContentStr = woody.EncodeBase64(ContentStr)
                cookie.Values("con") = ContentStr
            End If

        Else   '讀取 cookies
            If Not Request.Cookies("chatbox") Is Nothing Then
                Dim cookie As HttpCookie
                ContentStr = Request.Cookies("chatbox").Values("con")
                ContentStr = woody.DecodeBase64(ContentStr)
                Response.Write(ContentStr)
            Else
                Response.Write("N")
            End If

        End If

 

 

c#版本代碼
public string EncodeBase(string s)
{
string strResult = "";
if (s != "" && s != null)
{
strResult
= Convert.ToBase64String(System.Text.ASCIIEncoding.Default.GetBytes(s));
}
return strResult;
}
public string DecodeBase(string s)
{
string strResult = "";
if (s != "" && s != null)
{
strResult
= System.Text.ASCIIEncoding.Default.GetString(Convert.FromBase64String(s));
}
return strResult;
}
private void Page_Load(object sender, System.EventArgs e)
{
string vType ;
vType
=Request["vtype"];
string ContentStr;
//保存
if(vType=="SaveCookies")
{
ContentStr
= Request["con"];
if(Response.Cookies["chatbox"]!=null)
{
HttpCookie cookie
=Response.Cookies["chatbox"];
DateTime dt
=DateTime.Now ;
TimeSpan ts
=new TimeSpan(0,1,0);
cookie.Expires
= dt.Add(ts);
cookie.Values[
"con"] = EncodeBase(ContentStr);
Response.Cookies.Add(cookie);
}
else
{
HttpCookie cookie
= Response.Cookies["chatbox"];
ContentStr
=EncodeBase(ContentStr);
cookie.Values[
"con"] = ContentStr;
}

}
else
{
//讀取
if(Request.Cookies["chatbox"] !=null)
{

ContentStr
= Request.Cookies["chatbox"].Values["con"];
ContentStr
= DecodeBase(ContentStr);
}
else
{

}
}

}
woody.wu | 园豆:3621 (老鸟四级) | 2009-11-16 14:30
0

http://www.cnblogs.com/sufei/archive/2009/06/12/1502046.html

我这里有一个Cooke的应用,可以来看一下,呵呵感觉还是很不错的

苏飞 | 园豆:2024 (老鸟四级) | 2009-11-16 20:02
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册