problem with cookies

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sewen

    #1

    problem with cookies

    Dear all,
    I got a problem when i tried to access cookie in my project.
    There are 2 pages in the project:a.aspx and b.aspx.
    In a.aspx,i put the fololowing scripts:
    function SetCookie(name, value
    {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp .getTime() + 24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" +
    exp.toGMTString ();
    }
    ...
    SetCookie("List 1", list1) ;
    in a included js file i make a http_request to the b.aspx

    in b.aspx.cs i use the bellow code to access the cookie:
    HttpCookie cookie =Request.Cookie s["List1"];\
    if(cookie!=null )
    strIDList=HttpU tility.UrlDecod e(cookie.Value) ;
    when i run the project in visual studio(by F5),it works properly both in
    debug and release configuration.

    but when i visit the pages directly outsied of the visual studio,i
    fails.the value of strIDList is "".

    How does this happen and how to resolve it?
    I'm using visual studio 2003,Windows XP/2003.


    Thanks.




  • =?Utf-8?B?YnJ1Y2UgYmFya2Vy?=

    #2
    RE: problem with cookies

    if you are using XmlHttpRequest, you should use
    setRequestheade r("Cookie",valu e) to send cookies.

    note: while you can send a cookie via XmlHttpRequest, it does not apply any
    cookie value in the response.


    -- bruce (sqlwork.com)


    "sewen" wrote:
    Dear all,
    I got a problem when i tried to access cookie in my project.
    There are 2 pages in the project:a.aspx and b.aspx.
    In a.aspx,i put the fololowing scripts:
    function SetCookie(name, value
    {
    var Days = 30;
    var exp = new Date();
    exp.setTime(exp .getTime() + 24*60*60*1000);
    document.cookie = name + "="+ escape (value) + ";expires=" +
    exp.toGMTString ();
    }
    ...
    SetCookie("List 1", list1) ;
    in a included js file i make a http_request to the b.aspx
    >
    in b.aspx.cs i use the bellow code to access the cookie:
    HttpCookie cookie =Request.Cookie s["List1"];\
    if(cookie!=null )
    strIDList=HttpU tility.UrlDecod e(cookie.Value) ;
    when i run the project in visual studio(by F5),it works properly both in
    debug and release configuration.
    >
    but when i visit the pages directly outsied of the visual studio,i
    fails.the value of strIDList is "".
    >
    How does this happen and how to resolve it?
    I'm using visual studio 2003,Windows XP/2003.
    >
    >
    Thanks.
    >
    >
    >
    >
    >

    Comment

    • Alexey Smirnov

      #3
      Re: problem with cookies

      On Nov 10, 3:14 pm, "sewen" <se...@cn99.com wrote:
      Dear all,
          I got a problem when i tried to access cookie in my project.
          There are 2 pages in the project:a.aspx and b.aspx.
          In a.aspx,i put the fololowing scripts:
              function SetCookie(name, value
              {
              var Days = 30;
              var exp = new Date();
              exp.setTime(exp .getTime() + 24*60*60*1000);
              document.cookie = name + "="+ escape (value) + ";expires=" +
      exp.toGMTString ();
              }
              ...
              SetCookie("List 1", list1) ;
      Did you check the value of list1?

      Comment

      • sewen

        #4
        Re: problem with cookies

        thanks for the reply.I've resolve the problem by set the path of the
        cookie.
        "bruce barker" <brucebarker@di scussions.micro soft.comдÈëÏûÏ ¢ÐÂÎÅ:F1DA899D-9A24-4FC3-8B2C-D17E1A69824D@mi crosoft.com...
        if you are using XmlHttpRequest, you should use
        setRequestheade r("Cookie",valu e) to send cookies.
        >
        note: while you can send a cookie via XmlHttpRequest, it does not apply
        any
        cookie value in the response.
        >
        >
        -- bruce (sqlwork.com)
        >
        >
        "sewen" wrote:
        >
        >Dear all,
        > I got a problem when i tried to access cookie in my project.
        > There are 2 pages in the project:a.aspx and b.aspx.
        > In a.aspx,i put the fololowing scripts:
        > function SetCookie(name, value
        > {
        > var Days = 30;
        > var exp = new Date();
        > exp.setTime(exp .getTime() + 24*60*60*1000);
        > document.cookie = name + "="+ escape (value) + ";expires=" +
        >exp.toGMTStrin g();
        > }
        > ...
        > SetCookie("List 1", list1) ;
        > in a included js file i make a http_request to the b.aspx
        >>
        > in b.aspx.cs i use the bellow code to access the cookie:
        > HttpCookie cookie =Request.Cookie s["List1"];\
        > if(cookie!=null )
        > strIDList=HttpU tility.UrlDecod e(cookie.Value) ;
        > when i run the project in visual studio(by F5),it works properly both
        >in
        >debug and release configuration.
        >>
        > but when i visit the pages directly outsied of the visual studio,i
        >fails.the value of strIDList is "".
        >>
        > How does this happen and how to resolve it?
        > I'm using visual studio 2003,Windows XP/2003.
        >>
        >>
        > Thanks.
        >>
        >>
        >>
        >>
        >>
        >

        Comment

        Working...