943,603 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 2607
  • C# RSS
Dec 2nd, 2008
0

C# and Cookies problem

Expand Post »
hi,

ihave this code in c# for crating cookies :

if (saveInCokies_CheckBox.Checked)
{
HttpCookie myCookie = new HttpCookie("AtterehWebCookies");
myCookie["userName"] = userName_TextBox.Text.Trim();
myCookie["password"] = password_TextBox.Text.Trim();
if(employee_RadioButton.Checked)
myCookie["loginType"] = "employee";
else if(lawyer_RadioButton.Checked)
myCookie["loginType"] = "lawyer";
else if(customer_RadioButton.Checked)
myCookie["loginType"] = "customer";

Response.Cookies.Clear();
Response.Cookies.Add(myCookie);
Response.Cookies["AtterehWebCookies"].Expires = DateTime.Now.AddDays(30);

}

after that i want to read that cookies then iused this code:


if (Request.Cookies["AtterehWebCookies"] != null)
{
if (Request.Cookies["AtterehWebCookies"]["userName"] != null &
Request.Cookies["AtterehWebCookies"]["password"] != null &
Request.Cookies["AtterehWebCookies"]["loginType"] != null)
{
userName_TextBox.Text = Request.Cookies["AtterehWebCookies"]["userName"];
password_TextBox.Text = Request.Cookies["AtterehWebCookies"]["password"];

if (Request.Cookies["AtterehWebCookies"]["loginType"].Equals("employee"))
{
employee_RadioButton.Checked = true;
lawyer_RadioButton.Checked = false;
customer_RadioButton.Checked = false;
}
else if (Request.Cookies["AtterehWebCookies"]["loginType"].Equals("lawyer"))
{
lawyer_RadioButton.Checked = true;
employee_RadioButton.Checked = false;
customer_RadioButton.Checked = false;
}
else if (Request.Cookies["AtterehWebCookies"]["loginType"].Equals("customer"))
{
customer_RadioButton.Checked = true;
lawyer_RadioButton.Checked = false;
employee_RadioButton.Checked = false;
}
login_Button_Click(sender, e);
}
}

this two codes worked will for period of time but after that they does not worke and always give me Request.Cookies["AtterehWebCookies"] != null

any one can helpe me plz i thik that after 30 days the cookies are Expired what should i to do to let it worke again
Similar Threads
Reputation Points: 10
Solved Threads: 0
Light Poster
IT_Techno is offline Offline
41 posts
since Dec 2007
Dec 2nd, 2008
0

Re: C# and Cookies problem

If server side the cookies only valid 30 days, you would need to make them go through the process to generate a new valid one
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 2nd, 2008
0

Re: C# and Cookies problem

Click to Expand / Collapse  Quote originally posted by LizR ...
If server side the cookies only valid 30 days, you would need to make them go through the process to generate a new valid one

hi ,

how can i make them go through the process
Reputation Points: 10
Solved Threads: 0
Light Poster
IT_Techno is offline Offline
41 posts
since Dec 2007
Dec 2nd, 2008
0

Re: C# and Cookies problem

Well.. Generally the cookies created when they login, so you'd probably have to log them in. I dont know - ask the owner of the site
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Dec 3rd, 2008
0

Re: C# and Cookies problem

Click to Expand / Collapse  Quote originally posted by LizR ...
Well.. Generally the cookies created when they login, so you'd probably have to log them in. I dont know - ask the owner of the site

i did that but it does not worke i have removed the expire code and changed the cookies file name but it does not worke
Last edited by IT_Techno; Dec 3rd, 2008 at 9:28 am.
Reputation Points: 10
Solved Threads: 0
Light Poster
IT_Techno is offline Offline
41 posts
since Dec 2007
Dec 3rd, 2008
0

Re: C# and Cookies problem

most cookies have a default expirey.. Any currently set cookie will keep its old expirey by default too.
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: decimal places & asterisk help
Next Thread in C# Forum Timeline: image in listView





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC