I am building a login control using forms authentication and am using the UserDate in the Ticket so therefore need to write the Ticket cookie manually.
I am setting my cookie to expire in 50 years (i.e. persistant :) ) but when I read it back I get the following (i.e. with completely wrong expiry date/time):
Cookie: .ASPXAUTH
Expires: 01/01/0001 00:00:00
Secure: False
Value: D2015AD3DEF04C677547577DCEDED29CADDA533432F2F9EB78C0061273C037B16C889209 4A0471AA49C6AFC5696DEFD420DDFDC6A630F3C2375BB0154AFC9E0DA8D0B3FDE019F19C52E4DB A52CEF16DD
I am using the following code to read the cookie and am wondering if there is something wrong with it?
int loop1, loop2;
HttpCookieCollection MyCookieColl;
HttpCookie MyCookie;
MyCookieColl = Request.Cookies;
// Capture all cookie names into a string array.
String[] arr1 = MyCookieColl.AllKeys;
// Grab individual cookie objects by cookie name.
for (loop1 = 0; loop1 < arr1.Length; loop1++)
{
MyCookie = MyCookieColl[arr1[loop1]];
Content.Text += "Cookie: " + MyCookie.Name + "<br>";
Content.Text += "Expires: " + MyCookie.Expires + "<br>";
Content.Text += "Secure:" + MyCookie.Secure + "<br>";
//Grab all values for single cookie into an object array.
String[] arr2 = MyCookie.Values.AllKeys;
//Loop through cookie Value collection and print all values.
for (loop2 = 0; loop2 < arr2.Length; loop2++)
{
Content.Text += "Value" + loop2 + ": " + Server.HtmlEncode(arr2[loop2]) + "<br>";
}
}
Edited by SomeNewKid. Please post code between
<code> and
</code> tags.
www.creative-dreaming.com | www.independent-investor.com | www.buffettcup.com | www.thepropertyinvestmentshop.co.uk