Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > ASP.NET and ASP > ASP.NET 3.5 > ASP.NET 3.5 Basics
Password Reminder
Register
Register | FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
ASP.NET 3.5 Basics If you are new to ASP or ASP.NET programming with version 3.5, this is the forum to begin asking questions. Please also see the Visual Web Developer 2008 forum.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP.NET 3.5 Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developersí questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
 
 
Thread Tools Display Modes
  #1 (permalink)  
Old August 17th, 2009, 10:08 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default How to add an expiry date to Asp.net Membership cookie?

Hi

I want to make a remember me function for my site.

I believe if i use

FormsAuthentication.SetAuthCookie("userName", true);

this would do what I want right? But I want to make it a 2 week season not till they clear it what I believe this line would do.

I am not using any of the severside controls from asp.net since I am using asp.net mvc. Also even some of membership methods such as verify() and Create() I have made my own since they did not meet my needs.


I tried to grab the .ASPXAUTH but I don't know if changing the expiry date will do what I want. Or if it will even let me.


Thanks
  #2 (permalink)  
Old August 17th, 2009, 11:14 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

You need to set the expiration date of the cookie. You can do that in the web.config.

Code:
<system.web>
  <authentication mode="Forms">
    <forms loginUrl="Login.aspx"
           protection="All"
           timeout="20160"
           name=".ASPXAUTH" 
           path="/"
           requireSSL="false"
           slidingExpiration="false"
           defaultUrl="default.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false" />
  </authentication>
</system.web>
Here, the timeout is set to 20,160 minutes, which is 2 weeks. Whenever the cookie is set with a second parameter of true, this will set a persistent cookie with an expiration time of exactly two weeks from the time it was set.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #3 (permalink)  
Old August 17th, 2009, 11:48 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Lee Dumond View Post
You need to set the expiration date of the cookie. You can do that in the web.config.

Code:
<system.web>
  <authentication mode="Forms">
    <forms loginUrl="Login.aspx"
           protection="All"
           timeout="20160"
           name=".ASPXAUTH" 
           path="/"
           requireSSL="false"
           slidingExpiration="false"
           defaultUrl="default.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false" />
  </authentication>
</system.web>
Here, the timeout is set to 20,160 minutes, which is 2 weeks. Whenever the cookie is set with a second parameter of true, this will set a persistent cookie with an expiration time of exactly two weeks from the time it was set.
but according to this site
http://weblogs.asp.net/scottgu/archi...08/430011.aspx

everytime they come to the site it gets rest. That means if they keep coming every day it keeps getting extended.
  #4 (permalink)  
Old August 17th, 2009, 11:54 PM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Yes, it will be reset upon every request by default, because by default, slidingExpiration="true".

That's why I set slidingExpiration="false" in the example I posted. When you set this to "false", the expiration will not be reset.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #5 (permalink)  
Old August 17th, 2009, 11:57 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

Quote:
Originally Posted by Lee Dumond View Post
Yes, it will be reset upon every request by default, because by default, slidingExpiration="true".

That's why I set slidingExpiration="false" in the example I posted. When you set this to "false", the expiration will not be reset.
Ah ok. So I guess if I don't check the box(ie turn CookieAuth to false) then it is by session.
  #6 (permalink)  
Old August 18th, 2009, 12:01 AM
Lee Dumond's Avatar
Wrox Author
Points: 4,942, Level: 29
Points: 4,942, Level: 29 Points: 4,942, Level: 29 Points: 4,942, Level: 29
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jan 2008
Location: Decatur, IL, USA.
Posts: 923
Thanks: 12
Thanked 166 Times in 162 Posts
Default

Yes, that is correct.
__________________
Visit my blog at http://leedumond.com
Follow me on Twitter: http://twitter.com/LeeDumond

Code:
if (this.PostHelpedYou)
{
   ClickThanksButton(); 
}
  #7 (permalink)  
Old August 19th, 2009, 05:10 PM
Friend of Wrox
 
Join Date: Sep 2007
Location: , , .
Posts: 169
Thanks: 7
Thanked 2 Times in 2 Posts
Default

thanks it seems to have worked. I have not had tons of time to fully test it out and stuff and it might be a while. If something changes I will be back asking again
 


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Help with ASP.NET Membership VerbatimBOT SQL Server 2000 6 May 2nd, 2007 02:58 PM
change cookie expiry ab_dev Beginning PHP 0 March 9th, 2006 07:21 PM
Cookie Updating in ASP.NET br_r14 Classic ASP Basics 1 May 5th, 2005 07:55 PM
asp.net webpage expiry? imsuneeta General .NET 1 January 8th, 2005 08:23 AM
Cookie btw. ASP and .NET collie VB.NET 2002/2003 Basics 5 November 10th, 2003 09:38 AM



All times are GMT -4. The time now is 10:33 PM.


Powered by vBulletin®
Copyright ©2000 - 2018, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.