<html>  <script language="VB" runat="server">      Sub Page_Load(Sender As Object, E As EventArgs)        If Request.Cookies("preferences1") Is Nothing          Dim Cookie As HttpCookie
          Cookie = New HttpCookie("preferences1")
          Cookie.Values.Add("ForeColor","black")
          Cookie.Values.Add("BackColor","beige")
          Cookie.Values.Add("LinkColor","blue")
          Cookie.Values.Add("FontSize","8pt")
          Cookie.Values.Add("FontName","Verdana")
          Response.AppendCookie(Cookie)
        End If
      End Sub      Protected Function GetStyle(Key As String) As String        Dim Cookie As HttpCookie
        Cookie = Request.Cookies("preferences1")        If Not Cookie Is Nothing          Select (Key)            Case "ForeColor" :
              Return Cookie.Values("ForeColor")            Case "BackColor" :
              Return Cookie.Values("BackColor")            Case "LinkColor" :
              Return Cookie.Values("LinkColor")            Case "FontSize" :
              Return Cookie.Values("FontSize")            Case "FontName" :
              Return Cookie.Values("FontName")
          End Select
        End If        Return ""
      End Function  </script>  <style>    body {
      font: <%=GetStyle("FontSize")%> <%=GetStyle("FontName")%>;
      background-color: <%=GetStyle("BackColor")%>;
    }    a { color: <%=GetStyle("LinkColor")%> }  </style>  <body style="color:<%=GetStyle("ForeColor")%>">    <h3><font face="Verdana">Storing Volatile Data with Client-Side Cookies</font></h3>    <b><a href="customize.aspx">Customize This Page</a></b><p>    Imagine some content here ...<br>
    Imagine some content here ...<br>
    Imagine some content here ...<br>
    Imagine some content here ...<br>
    Imagine some content here ...<br>
    Imagine some content here ...<br>
    Imagine some content here ...<br>
    Imagine some content here ...<br>  </body></html>

解决方案 »

  1.   


    //因为不能在类中写过程,只好在这里引用写Cookies
    HttpCookie cookie = new HttpCookie(XnFlag);
    cookie.Value = “cookievalue;”
    Response.Cookies.Add(cookie);
    取值
    HttpCookie cookieU = Request.Cookies["XnFlag"];
    strCookieU= cookieU.Value.ToString();
      

  2.   

    谢谢各位,我用的是C#,用“
    HttpCookie cookieU = Request.Cookies["XnFlag"];
    strCookieU= cookieU.Value.ToString();”
    这样取值取的是cook的文本文件里的值,如果cook不记录在文本文件里,我只是在两个或三个文件里用cook传递值,就象Session那样,在一个页面里得到另一个页面传过来的cook的值,应该怎么写呀?用Request.Cookies["cookname"]可以,但是怎么得到这个值,不能把它直接用String或Int定义的变量来取,请问应该用什么呀,谢谢。