problem with cookies

Discussion in 'ASP .Net' started by sewen, Nov 10, 2008.

  1. sewen

    sewen Guest

    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("List1", 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.Cookies["List1"];\
    if(cookie!=null)
    strIDList=HttpUtility.UrlDecode(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.
    sewen, Nov 10, 2008
    #1
    1. Advertising

  2. sewen

    bruce barker Guest

    if you are using XmlHttpRequest, you should use
    setRequestheader("Cookie",value) 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("List1", 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.Cookies["List1"];\
    > if(cookie!=null)
    > strIDList=HttpUtility.UrlDecode(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.
    >
    >
    >
    >
    >
    bruce barker, Nov 10, 2008
    #2
    1. Advertising

  3. On Nov 10, 3:14 pm, "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("List1", list1) ;


    Did you check the value of list1?
    Alexey Smirnov, Nov 10, 2008
    #3
  4. sewen

    sewen Guest

    thanks for the reply.I've resolve the problem by set the path of the
    cookie.
    "bruce barker" <> дÈëÏûÏ¢ÐÂÎÅ:...
    > if you are using XmlHttpRequest, you should use
    > setRequestheader("Cookie",value) 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("List1", 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.Cookies["List1"];\
    >> if(cookie!=null)
    >> strIDList=HttpUtility.UrlDecode(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.
    >>
    >>
    >>
    >>
    >>

    >
    sewen, Nov 11, 2008
    #4
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Alex Nitulescu

    Response.Cookies vs Request.Cookies

    Alex Nitulescu, Feb 3, 2005, in forum: ASP .Net
    Replies:
    1
    Views:
    8,486
    Hans Kesting
    Feb 3, 2005
  2. Andy Fish
    Replies:
    3
    Views:
    6,526
    Fredrik Lindner
    Nov 6, 2003
  3. user
    Replies:
    3
    Views:
    663
    =?ISO-8859-1?Q?G=F6ran_Andersson?=
    Mar 31, 2007
  4. archana
    Replies:
    1
    Views:
    506
  5. _Who
    Replies:
    7
    Views:
    2,660
Loading...

Share This Page