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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cookies do not seem to save

Status
Not open for further replies.

jmeckley

Programmer
Jul 15, 2002
5,269
0
0
US
I have a form that creates a cookie and saves it to the users computer. The user is then redirected to another page.

Depending on options in the cookie cretain objects will be visible.

Here is my code
FORM 1
Code:
Dim Cookie As New HttpCookie("AnswerService")
Dim Pwd As String = txtPwd.Text

Cookie.Values.Add("Pwd", Pwd)
Response.Cookies.Add(Cookie)
Response.Redirect("../")
FORM2
Code:
If Request.Cookies("AnswerService") Is Nothing Then 'no cookie (web pledge)
    chkBillMe.Visible = False
    rfvBillMe.Visible = False
Else 'cookie = test for answer service
    Dim Cookie As HttpCookie = Request.Cookies("AnswerService")
    
    If Cookie.Item("Pwd") = "123" Then 'hide cc and exp date validation
        rfvCC_1.Visible = False
        rfvExpMonth.Visible = False
        rfvExpYear.Visible = False
        rfvExpDate.Visible = False
    Else 'not answering service
        chkBillMe.Visible = False
        rfvBillMe.Visible = False
    End If
End If

This code will work while the broswer is open. But When I close the browser and open it back up the code executes as if no cookie is present. What am I missing in my code?

I am using VS 2003 with .Net Framework 1.1

Jason Meckley
Database Analyst
WITF
 
So It's working now. I am using Response.AppendCookie instead of Response.Cookie.Add. I also added an expiration date of Date.MaxValue. Seems to do the trick.

Jason Meckley
Database Analyst
WITF
 
Hi Jason,

Can you post your code for setting the cookie.
Im having trouble and cookies really wind me up some time!

Rich

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top