How do you read persistent cookies?

G

Guest

Ok. I know this sounds like a stupid question, but I'm really beside myself
here. I've worked with cookies for years, so I know how they work, but I am
new to C#, so apparently I'm doing something wrong with C#.

I'm saving a cookie (user preferences) that I want to load again the next
time a user visits my site. I know it's saving correctly, I can see it in
the temporary internet files. But my first page (Default.aspx) is trying to
read it from Request.Cookies and it's not there. There must be a trick to
reading in this cookie file. Ok. What is the trick? How do I pull the
saved cookies back in and/or how do I read them?
 
W

www.VoiceInformation.com

Here's some sample C# cookie code that is working for me:

Sample C# Code:
const stringNAME_COOKIE = "YourCookieName";
const stringNAME_USERID = "inpUserIDField";
const stringNAME_SERVER = "inpServerField";

private void Page_Load(object sender, System.EventArgs e)
{
// Retrieve settings from last visit
try
{
if (Request.Cookies != null)
{
inpUserID.Value =
Server.HtmlEncode(Request.Cookies[NAME_COOKIE][NAME_USERID]).ToString();
inpServer.Value =
Server.HtmlEncode(Request.Cookies[NAME_COOKIE][NAME_SERVER]).ToString();
}
}
catch {}
}

private void Submit_ServerClick(object sender, System.EventArgs e)
{
// Save user settings
try
{
Response.Cookies[NAME_COOKIE][NAME_USERID] = inpUserID.Value;
Response.Cookies[NAME_COOKIE][NAME_SERVER] = inpServer.Value;
Response.Cookies[NAME_COOKIE].Expires = DateTime.MaxValue;
}
catch {}
}


www.VoiceInformation.com . . . . . . . . . . . . <a
href="http://www.VoiceInformation.com">
Virtual Office, Automated Personal Phone Assistant, Follow-Me VMail Web
Messaging </a><br>

www.TekGuard.com . . . . . . . . . . . . . . . . . . . . <a
href="http://www.TekGuard.com">
Free Mail Server, AntiSpam, PlugIn, WebMail, Free Source Code,
Unlimited Users/Domain </a>
 

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

Similar Threads


Members online

Forum statistics

Threads
473,768
Messages
2,569,574
Members
45,050
Latest member
AngelS122

Latest Threads

Top