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

Advertisements

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?
 
Ad

Advertisements

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

Top