Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookie Not Saved 1

Status
Not open for further replies.

kentover

MIS
Aug 21, 2002
41
US
I have gone through many threads to try and correct my code but it seems the same as the solutions suggested. I am getting no errors and have stepped through the code. Each line seems to be executed but ultimately the cookie is not created. Here is the code:

Dim Cookie As HttpCookie
If Request.Cookies("StoreUserID") Is Nothing
Cookie = New HttpCookie("StoreUserID")
Cookie.Values.Add("UserID",cstr(intUsrID))
Cookie.Values.Add("UserLgn",LoginID.Text)
Cookie.Values.Add("UserPswd",UserPwd.Text)
'Response.Cookies.Add(Cookie)
Response.AppendCookie(Cookie)
end if
 
Have you looked at the raw http headers the page is returning? Depending on your browser, it may do this for you, but if all else fails, you can just "telnet webserver:80" and type "GET page.aspx" and see what comes back. The very top should be a list of headers, some of which are cookies.

Though to be honest, I've never actually formally made a cookie object. It seems to do fine creating it on its own.
Code:
If Request.Cookies("StoreUserID") Is Nothing
    Response.Cookies("StoreUserID")("UserID") = cstr(intUsrID)
    Response.Cookies("StoreUserID")("UserLgn") = LoginID.Text
    Response.Cookies("StoreUserID")("UserPswd") = UserPwd.Text
End If
I guess if you don't explicitly set an expiration for the cookie, it's probably just a session cookie. The http headers should tell you that, too.

When debugging your current code, does the Response.Cookies collection contain your new cookie after you create and add it?

________________________________________
Andrew

I work for a gift card company!
 
Try this:
Code:
If Request.Cookies("StoreUserID") Is Nothing Then
    Dim Cookie As HttpCookie = New HttpCookie("StoreUserID")
    Cookie.Values("UserID") = CStr(intUsrID)
    Cookie.Values("UserLgn") = LoginID.Text
    Cookie.Values("UserPswd") = UserPwd.Text
    Cookie.Expires = System.DateTime.Now.AddDays(1)
    Response.Cookies.Add(Cookie)
End If

----------------------------------------------------------------------

Need help finding an answer?

Try the search facilty ( or read FAQ222-2244 on how to get better results.
 
You guys are great! It was the combination of the two answers. Thank you for your help. Here is the code.


Response.Cookies("StoreUserID")("UserID") = cstr(intUsrID)
Response.Cookies("StoreUserID")("UserLgn") = LoginID.Text
Response.Cookies("StoreUserID")("UserPswd") = UserPwd.Text
Response.Cookies("StoreUserID").Expires = System.DateTime.Now.AddDays(1)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top