Cookie problem

B

Bill Nicholson

Maybe I don't understand cookies correctly. When some visits my site
and logs in, they get a cookie that stores their login information.
When they come back, that info is read from the cookie and they can
log in without having to remember their id/pw.

Assume the site is www.foobar.com It works as long as they browse to
www.foobar.com. If they browse to foobar.com it doesn't see the
cookie. It they browse to www.foobar.com/Stuff.aspx, it doesn't see
the cookie.

What am I missing? Do I need to store the cookie differently?

Response.Cookies("CookieName").Value =
tmpObject.Text.Trim
Response.Cookies("CookieName").Expires =
DateTime.Now.AddDays(1000)

The cookie looks fine - I checked it through the browsers (IE 6 and
FireFox).

Thanks,

Bill
Cincinnati, OH USA
 
G

Guest

Maybe I don't understand cookies correctly. When some visits my site
and logs in, they get a cookie that stores their login information.
When they come back, that info is read from the cookie and they can
log in without having to remember their id/pw.

Assume the site iswww.foobar.comIt works as long as they browse towww.foobar.com. If they browse to foobar.com it doesn't see the
cookie. It they browse towww.foobar.com/Stuff.aspx, it doesn't see
the cookie.

What am I missing? Do I need to store the cookie differently?

Response.Cookies("CookieName").Value =
tmpObject.Text.Trim
Response.Cookies("CookieName").Expires =
DateTime.Now.AddDays(1000)

The cookie looks fine - I checked it through the browsers (IE 6 and
FireFox).

Thanks,

Bill
Cincinnati, OH USA

Hi Bill,

add Trace="true" to the @Page directive at the start of the page, then
you should see details of your cookies

<%@ Page Trace="true" ... %>

Hope this helps to find the problem
 
L

Laurent Bugnion, MVP

Hi,

Bill said:
Maybe I don't understand cookies correctly. When some visits my site
and logs in, they get a cookie that stores their login information.
When they come back, that info is read from the cookie and they can
log in without having to remember their id/pw.

Assume the site is www.foobar.com It works as long as they browse to
www.foobar.com. If they browse to foobar.com it doesn't see the
cookie. It they browse to www.foobar.com/Stuff.aspx, it doesn't see
the cookie.

Make sure you set the Cookie's path correctly. If you want the cookie to
be visible on your whole site, you must set the path to "/".
http://msdn2.microsoft.com/en-us/library/system.net.cookie.path.aspx

HTH,
Laurent
 
E

Eliyahu Goldin

Well, there can be a problem if the path is set in anything different from
"/", There shouldn't be a problem if the path is not set at all. At the msdn
states:

If this property is not specified, then this Cookie will be sent to all
pages on the origin server or servers.

--
Eliyahu Goldin,
Software Developer
Microsoft MVP [ASP.NET]
http://msmvps.com/blogs/egoldin
http://usableasp.net


Laurent Bugnion said:
Hi,

Bill said:
Maybe I don't understand cookies correctly. When some visits my site
and logs in, they get a cookie that stores their login information.
When they come back, that info is read from the cookie and they can
log in without having to remember their id/pw.

Assume the site is www.foobar.com It works as long as they browse to
www.foobar.com. If they browse to foobar.com it doesn't see the
cookie. It they browse to www.foobar.com/Stuff.aspx, it doesn't see
the cookie.

Make sure you set the Cookie's path correctly. If you want the cookie to
be visible on your whole site, you must set the path to "/".
http://msdn2.microsoft.com/en-us/library/system.net.cookie.path.aspx

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog: http://www.galasoft.ch
PhotoAlbum: http://www.galasoft.ch/pictures
Support children in Calcutta: http://www.calcutta-espoir.ch
 
L

Laurent Bugnion, MVP

Hi,

Eliyahu said:
Well, there can be a problem if the path is set in anything different from
"/", There shouldn't be a problem if the path is not set at all. At the msdn
states:

If this property is not specified, then this Cookie will be sent to all
pages on the origin server or servers.

That would mean that the default value is "/". Anyway, the symptom being
that the cookie is not visible on all pages, this rather points to a
problem with the Path.

Greetings,
Laurent
 
B

Bill Nicholson

If the path is not specified, then it defaults to '/'. And I am not
specifying it. So what's the problem?

Hi,

Eliyahu said:
Well, there can be a problem if the path is set in anything different from
"/", There shouldn't be a problem if the path is not set at all. At the msdn
states:
If this property is not specified, then this Cookie will be sent to all
pages on the origin server or servers.

That would mean that the default value is "/". Anyway, the symptom being
that the cookie is not visible on all pages, this rather points to a
problem with the Path.

Greetings,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog:http://www.galasoft.ch
PhotoAlbum:http://www.galasoft.ch/pictures
Support children in Calcutta:http://www.calcutta-espoir.ch
 
L

Laurent Bugnion, MVP

Hi,

Bill said:
If the path is not specified, then it defaults to '/'. And I am not
specifying it. So what's the problem?

No problems on my side. You described a symptom, I described the most
common cause for it. We've got to start somewhere.

On the client side, when you watched document.cookie, what does the
cookie string look like, and is the "path" part set?

HTH,
Laurent
 
B

Bill Nicholson

Sorry, Laurent. I meant "What's the problem with my cookie". I wasn't
flaming you. My bad!

Hi,

Bill said:
If the path is not specified, then it defaults to '/'. And I am not
specifying it. So what's the problem?

No problems on my side. You described a symptom, I described the most
common cause for it. We've got to start somewhere.

On the client side, when you watched document.cookie, what does the
cookie string look like, and is the "path" part set?

HTH,
Laurent
--
Laurent Bugnion [MVP ASP.NET]
Software engineering, Blog:http://www.galasoft.ch
PhotoAlbum:http://www.galasoft.ch/pictures
Support children in Calcutta:http://www.calcutta-espoir.ch
 
L

Laurent Bugnion, MVP

Hi,

Bill said:
Sorry, Laurent. I meant "What's the problem with my cookie". I wasn't
flaming you. My bad!

No worries Bill. I also wonder what's wrong with your cookie. YOu said
you checked the cookie in IE and Netscape, you mean you watched the
"document.cookie" JavaScript variable? Or what method did you use?

If you can, post the "document.cookie" string which is stored in the
client. You can do that using JavaScript in your web page. It would be
helpful to see what is really sent to the client, not just the
high-level API calls in ASP.NET.

HTH,
Laurent
 

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

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top