problem with cookies

  • Thread starter Thread starter sewen
  • Start date Start date
S

sewen

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.
 
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)
 
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?
 
thanks for the reply.I've resolve the problem by set the path of the
cookie.
bruce barker said:
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 said:
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.
 
Back
Top