problem with cookies

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.
 
B

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)
 
G

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) ;

Did you check the value of list1?
 
S

sewen

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads

Problem with reflection in C# 4
Cookies 1
Cookies 1
cookies not persisting 2
Cookies? 5
Encoding problem with cookies 0
Cookies can't be read 0
problem with cookies and graphics 0

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,014
Latest member
BiancaFix3

Latest Threads

Top