473,397 Members | 1,969 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,397 software developers and data experts.

Cookie expiration issues

SJ
Hi,

In my website, i have a cookie that allows the user to remain logged in for
upto 90days. So I'm setting the cookie expiration time to 90 days in the
future from the time the user logs in. I've been testing my code and for
some reason, the cookie expires randomly before even 24 hrs has passed.
Yesterday it expired after 11hrs and 20mins.

Any idea why my cookie expiration isn't working?

In case you need them, here are the values of other timeouts in my
machine.config and web.config files:
web.config -- sessionState timeout="60"
machine.config -- forms timeout="60", sessionState timeout="60"

thanks,
-SJ.


Nov 3 '06 #1
5 2200
Hi,
>
In my website, i have a cookie that allows the user to remain logged in for
upto 90days. So I'm setting the cookie expiration time to 90 days in the
future from the time the user logs in. I've been testing my code and for
some reason, the cookie expires randomly before even 24 hrs has passed.
Yesterday it expired after 11hrs and 20mins.

Any idea why my cookie expiration isn't working?

In case you need them, here are the values of other timeouts in my
machine.config and web.config files:
web.config -- sessionState timeout="60"
machine.config -- forms timeout="60", sessionState timeout="60"

thanks,
-SJ.
The other timeout settings have nothing to do with the cookie-timeout.

How do you set the expiration date of your cookie?

How do you see that "timeout"? It could be due to the user removing the
cookie (maybe by running a "cleanup junk" type of program)

Hans Kesting
Nov 3 '06 #2
SJ
I'm the user and I'm not removing hte cookie. I'm using a program that shows
cookie information(including when the cookie expired) for Internet Explorer.
I set my cookie through code as follows:
public static bool LoginUser(int aPersonID, string userRole, bool
persistentLogon)
{
try
{
// This is set in Web.Config <authenticationsection
string authCookieName = FormsAuthentication.FormsCookieName;
// Save crucial data in userData
string[] userDataArray = {aPersonID.ToString(), userRole};
string userData = String.Join("|", userDataArray);

// Standard authentication cookie is good for 60 minutes
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Version number
aPersonID.ToString(), // Name associated with ticket
System.DateTime.Now, // Time cookie issued
System.DateTime.Now.AddMinutes(60), // Expiration for cookie
persistentLogon, // Cookie persistence
userData, // User Data
FormsAuthentication.FormsCookiePath); // Cookie Path

// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);

HttpContext.Current.Response.Cookies[authCookieName].Value =
encTicket;
if (persistentLogon)
// Keep Authentication cookie around for 90 days
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddDays(90);// + new TimeSpan(90,0,0,0);
else
// Keep Authentication cookie around for 60 minutes
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddMinutes(60);// + new TimeSpan(0,0,60,0);

return (true);
}
catch(System.Threading.ThreadAbortException){}
catch(Exception ex)
{
Log.WriteException("Web.LoginUser()", ex);
}
return (false);
}// LoginUser()

"Hans Kesting" <ne***********@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
Hi,

In my website, i have a cookie that allows the user to remain logged in
for
upto 90days. So I'm setting the cookie expiration time to 90 days in the
future from the time the user logs in. I've been testing my code and for
some reason, the cookie expires randomly before even 24 hrs has passed.
Yesterday it expired after 11hrs and 20mins.

Any idea why my cookie expiration isn't working?

In case you need them, here are the values of other timeouts in my
machine.config and web.config files:
web.config -- sessionState timeout="60"
machine.config -- forms timeout="60", sessionState timeout="60"

thanks,
-SJ.

The other timeout settings have nothing to do with the cookie-timeout.

How do you set the expiration date of your cookie?

How do you see that "timeout"? It could be due to the user removing the
cookie (maybe by running a "cleanup junk" type of program)

Hans Kesting


Nov 3 '06 #3
SJ
Any idea anyone?

-SJ
"SJ" <my******@sbcglobal.netwrote in message
news:6D***************@newssvr12.news.prodigy.com. ..
I'm the user and I'm not removing hte cookie. I'm using a program that
shows
cookie information(including when the cookie expired) for Internet
Explorer.
I set my cookie through code as follows:
public static bool LoginUser(int aPersonID, string userRole, bool
persistentLogon)
{
try
{
// This is set in Web.Config <authenticationsection
string authCookieName = FormsAuthentication.FormsCookieName;
// Save crucial data in userData
string[] userDataArray = {aPersonID.ToString(), userRole};
string userData = String.Join("|", userDataArray);

// Standard authentication cookie is good for 60 minutes
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Version number
aPersonID.ToString(), // Name associated with ticket
System.DateTime.Now, // Time cookie issued
System.DateTime.Now.AddMinutes(60), // Expiration for cookie
persistentLogon, // Cookie persistence
userData, // User Data
FormsAuthentication.FormsCookiePath); // Cookie Path

// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);

HttpContext.Current.Response.Cookies[authCookieName].Value =
encTicket;
if (persistentLogon)
// Keep Authentication cookie around for 90 days
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddDays(90);// + new TimeSpan(90,0,0,0);
else
// Keep Authentication cookie around for 60 minutes
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddMinutes(60);// + new TimeSpan(0,0,60,0);

return (true);
}
catch(System.Threading.ThreadAbortException){}
catch(Exception ex)
{
Log.WriteException("Web.LoginUser()", ex);
}
return (false);
}// LoginUser()

"Hans Kesting" <ne***********@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
Hi,
>
In my website, i have a cookie that allows the user to remain logged
in
for
upto 90days. So I'm setting the cookie expiration time to 90 days in
the
future from the time the user logs in. I've been testing my code and
for
some reason, the cookie expires randomly before even 24 hrs has
passed.
Yesterday it expired after 11hrs and 20mins.
>
Any idea why my cookie expiration isn't working?
>
In case you need them, here are the values of other timeouts in my
machine.config and web.config files:
web.config -- sessionState timeout="60"
machine.config -- forms timeout="60", sessionState timeout="60"
>
thanks,
-SJ.
The other timeout settings have nothing to do with the cookie-timeout.

How do you set the expiration date of your cookie?

How do you see that "timeout"? It could be due to the user removing the
cookie (maybe by running a "cleanup junk" type of program)

Hans Kesting


Nov 7 '06 #4
The problem might lie in what you do after the LoginUser returns. I found
this thread because I was having a similar problem; after much debugging it
turned out that I was calling RedirectFromLoginPage, which could also set the
cookie (depending on the argument), and all the changes you've made to it
will be overwritten -- at least that was the problem in my case. The fix was
to call RedirectFromLoginPage, and THEN change Expires property. Either that,
or call Response.Redirect instead.

Also: check slidingExpiration setting in the <formssection of web.config.

Valery P.

"SJ" wrote:
Any idea anyone?

-SJ
"SJ" <my******@sbcglobal.netwrote in message
news:6D***************@newssvr12.news.prodigy.com. ..
I'm the user and I'm not removing hte cookie. I'm using a program that
shows
cookie information(including when the cookie expired) for Internet
Explorer.
I set my cookie through code as follows:
public static bool LoginUser(int aPersonID, string userRole, bool
persistentLogon)
{
try
{
// This is set in Web.Config <authenticationsection
string authCookieName = FormsAuthentication.FormsCookieName;
// Save crucial data in userData
string[] userDataArray = {aPersonID.ToString(), userRole};
string userData = String.Join("|", userDataArray);

// Standard authentication cookie is good for 60 minutes
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Version number
aPersonID.ToString(), // Name associated with ticket
System.DateTime.Now, // Time cookie issued
System.DateTime.Now.AddMinutes(60), // Expiration for cookie
persistentLogon, // Cookie persistence
userData, // User Data
FormsAuthentication.FormsCookiePath); // Cookie Path

// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);

HttpContext.Current.Response.Cookies[authCookieName].Value =
encTicket;
if (persistentLogon)
// Keep Authentication cookie around for 90 days
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddDays(90);// + new TimeSpan(90,0,0,0);
else
// Keep Authentication cookie around for 60 minutes
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddMinutes(60);// + new TimeSpan(0,0,60,0);

return (true);
}
catch(System.Threading.ThreadAbortException){}
catch(Exception ex)
{
Log.WriteException("Web.LoginUser()", ex);
}
return (false);
}// LoginUser()

"Hans Kesting" <ne***********@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
Hi,

In my website, i have a cookie that allows the user to remain logged
in
for
upto 90days. So I'm setting the cookie expiration time to 90 days in
the
future from the time the user logs in. I've been testing my code and
for
some reason, the cookie expires randomly before even 24 hrs has
passed.
Yesterday it expired after 11hrs and 20mins.

Any idea why my cookie expiration isn't working?

In case you need them, here are the values of other timeouts in my
machine.config and web.config files:
web.config -- sessionState timeout="60"
machine.config -- forms timeout="60", sessionState timeout="60"

thanks,
-SJ.
>
The other timeout settings have nothing to do with the cookie-timeout.
>
How do you set the expiration date of your cookie?
>
How do you see that "timeout"? It could be due to the user removing the
cookie (maybe by running a "cleanup junk" type of program)
>
Hans Kesting
>
>


Nov 22 '06 #5
Forgot to mention: you can always spy on the cookie you are setting in
C:\Documents and Settings\<user>\Local Settings\Temporary Internet Files.
Otherwise it's very difficult to debug. Sort by "Last Modified" to get it to
the top (or bottom) of the list.

VP

"SJ" wrote:
Any idea anyone?

-SJ
"SJ" <my******@sbcglobal.netwrote in message
news:6D***************@newssvr12.news.prodigy.com. ..
I'm the user and I'm not removing hte cookie. I'm using a program that
shows
cookie information(including when the cookie expired) for Internet
Explorer.
I set my cookie through code as follows:
public static bool LoginUser(int aPersonID, string userRole, bool
persistentLogon)
{
try
{
// This is set in Web.Config <authenticationsection
string authCookieName = FormsAuthentication.FormsCookieName;
// Save crucial data in userData
string[] userDataArray = {aPersonID.ToString(), userRole};
string userData = String.Join("|", userDataArray);

// Standard authentication cookie is good for 60 minutes
FormsAuthenticationTicket ticket = new FormsAuthenticationTicket(
1, // Version number
aPersonID.ToString(), // Name associated with ticket
System.DateTime.Now, // Time cookie issued
System.DateTime.Now.AddMinutes(60), // Expiration for cookie
persistentLogon, // Cookie persistence
userData, // User Data
FormsAuthentication.FormsCookiePath); // Cookie Path

// Encrypt the ticket.
string encTicket = FormsAuthentication.Encrypt(ticket);

HttpContext.Current.Response.Cookies[authCookieName].Value =
encTicket;
if (persistentLogon)
// Keep Authentication cookie around for 90 days
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddDays(90);// + new TimeSpan(90,0,0,0);
else
// Keep Authentication cookie around for 60 minutes
HttpContext.Current.Response.Cookies[authCookieName].Expires =
DateTime.Now.AddMinutes(60);// + new TimeSpan(0,0,60,0);

return (true);
}
catch(System.Threading.ThreadAbortException){}
catch(Exception ex)
{
Log.WriteException("Web.LoginUser()", ex);
}
return (false);
}// LoginUser()

"Hans Kesting" <ne***********@spamgourmet.comwrote in message
news:mn***********************@spamgourmet.com...
Hi,

In my website, i have a cookie that allows the user to remain logged
in
for
upto 90days. So I'm setting the cookie expiration time to 90 days in
the
future from the time the user logs in. I've been testing my code and
for
some reason, the cookie expires randomly before even 24 hrs has
passed.
Yesterday it expired after 11hrs and 20mins.

Any idea why my cookie expiration isn't working?

In case you need them, here are the values of other timeouts in my
machine.config and web.config files:
web.config -- sessionState timeout="60"
machine.config -- forms timeout="60", sessionState timeout="60"

thanks,
-SJ.
>
The other timeout settings have nothing to do with the cookie-timeout.
>
How do you set the expiration date of your cookie?
>
How do you see that "timeout"? It could be due to the user removing the
cookie (maybe by running a "cleanup junk" type of program)
>
Hans Kesting
>
>


Nov 22 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Christophe Lance | last post by:
Hello, I use PHP session cookie to store an id number. I know how to set a cookie expiration date using the setcookie function, but how to set an expiration date when the cookie is created by...
18
by: Paul | last post by:
I link to a web site from an Excel spreadsheet. The page i link to is getCookie.asp which sets a cookie then returns back some html which opens a new window, to the same site but a different page...
7
by: Christoph Pieper | last post by:
Hi, we've the following problem : We have an asp-application which sets the cookie on first login. The cookie will never be touched during user access. The user can work the whole day, but...
15
by: Oleg Leikin | last post by:
Hi, (newbie question) I've created some simple .NET ASP application that should store cookies at the client machine. According to the documentation cookie expiration time is set via...
0
by: Kepler | last post by:
I'm testing very basic FormsAuthentication and having trouble with non-persistent cookies. Once authenticated with a non-persistent cookie, if I leave the browser alone for 30 minutes,...
2
by: Bill Borg | last post by:
Hello all, I am working on forms authentication and trying to understand: what's the relationship between the cookie expiration and the ticket expiration? I create a cookie and I add an...
2
by: Jeff Bowman | last post by:
Here's the code: Private Sub SetCookie(ByVal tcEmail As String) Dim loCookie As New HttpCookie("Email") loCookie.Value = Utils.StringToBase64(tcEmail) loCookie.Expires = Now.AddYears(10)...
15
by: Edwin Knoppert | last post by:
I have searched but info is limitted. In my test app i used a non persistant cookie for forms authentication. slidingExpiration is set to true On run and close and rerun the login remains ok....
9
by: Mike Reed | last post by:
I must be having a "senile" day! I cannot recall, nor get to work, code to read a cookie's expiration date/time in an ASP page/VBScript. What am I missing? *** Sent via Developersdex...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.