<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://forums.asp.net/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>Security</title><link>http://forums.asp.net/25.aspx</link><description>All about ASP.NET security (authentication, authorization, membership, roles, etc.) and the Login controls. &lt;a href="http://aspadvice.com/SignUp/list.aspx?l=24&amp;c=17" target="_blank"&gt;Email List&lt;/a&gt;</description><dc:language>en</dc:language><generator>CommunityServer 2007 SP1 (Build: 20510.895)</generator><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/2282142.aspx</link><pubDate>Mon, 07 Apr 2008 21:53:08 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2282142</guid><dc:creator>sschack</dc:creator><author>sschack</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2282142.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2282142</wfw:commentRss><description>&lt;p&gt;Forms authentication only looks at the contents of the ticket because a malicious user client has control over all of the data sent in an HTTP request. However the forms authentication ticket itself is encrypted by ASP.NET and thus ASP.NET can trust its contents.&lt;/p&gt;&lt;p&gt;&amp;nbsp;If you set the timeout for a forms authentication ticket to 20 minutes, and you enable sliding expirations, then when a request arrives and ASP.NET determines that 10 minutes of life-time (or less) remains for the authentication ticket, ASP.NET will generate a new one with an updated expiration date.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/2282062.aspx</link><pubDate>Mon, 07 Apr 2008 20:56:04 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2282062</guid><dc:creator>haidar_bilal</dc:creator><author>haidar_bilal</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2282062.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2282062</wfw:commentRss><description>&lt;p&gt;Hello Stefan,&lt;/p&gt;
&lt;p&gt;The results came the same, the first time the application creates an authentication cookie, the cookie value, path, HttpOnly, and expirtation date are sent back to the client, while the next request has only the encrypted pay load or FormsAuthenticationTicket.&lt;/p&gt;
&lt;p&gt;What caught my attention is that inside the OnAuthenticate event, there is this code: &lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FormsAuthenticationTicket tOld = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; bool cookielessTicket = false;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; try&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tOld = ExtractTicketFromCookie(e.Context, FormsAuthentication.FormsCookieName, out cookielessTicket);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; catch&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; tOld = null;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&lt;br /&gt;And inside the ExtractTicketFromCookie,&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpCookie cookie = context.Request.Cookies[name];&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; if (cookie != null)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; {&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; encryptedTicket = cookie.Value;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; }&lt;/p&gt;
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;This shows that the FormsAuthenticationModule never looks at the expiration date of the cookie, it only makes sure there is an authentication cookie. So I guess, if the cookie is available, it will simply grab the FormsAuthenticationTicket, do the checkings on the ticket itself if valid or not, regardless of the request cookie.&lt;/p&gt;
&lt;p&gt;Finally, just wondering about this statement: &amp;quot;Since refreshing the ticket occurs at roughly the 50% point of the ticket&amp;#39;s time-to-live&amp;quot;&lt;/p&gt;
&lt;p&gt;Thanks a lot!&lt;br /&gt;Regards&lt;br /&gt;&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/2281972.aspx</link><pubDate>Mon, 07 Apr 2008 20:02:27 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2281972</guid><dc:creator>sschack</dc:creator><author>sschack</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2281972.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2281972</wfw:commentRss><description>&lt;p&gt;The behavior you are seeing is because when you access cookies from the Request object, the expiration date of the cookie is not available.&amp;nbsp; The client-side browsers retain the expiration date for each cookie stored in the browser cache - but that information is never sent over the wire when cookies are subsequently sent back to a server.&amp;nbsp; &lt;/p&gt;
&lt;p&gt;You can see that behavior by using a protocol trace tool like Fiddler and seeing what information is sent from the server to the browser the first time a cookie is issued.&amp;nbsp; Then compare that to the cookie being sent from the browser to the server on subsequent calls.&lt;/p&gt;
&lt;p&gt;I think the reflection code is from the part of OnAuthenticate that only runs if forms authentication detects the need to refresh the forms authentication ticket.&amp;nbsp; Since refreshing the ticket occurs at roughly the 50% point of the ticket&amp;#39;s time-to-live, the associated code in OnAuthenticate normally won&amp;#39;t run and hence the HttpCookie instance from the Request object won&amp;#39;t be touched.&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/2278401.aspx</link><pubDate>Sat, 05 Apr 2008 11:35:15 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2278401</guid><dc:creator>haidar_bilal</dc:creator><author>haidar_bilal</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2278401.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2278401</wfw:commentRss><description>&lt;p&gt;Hi Stefan,&lt;/p&gt;
&lt;p&gt;I am noticing a strange behavior in ASP.NET 3.5.&lt;/p&gt;
&lt;p&gt;I have added the following into the page_load of the Login.aspx page:&lt;/p&gt;
&lt;p&gt;FormsAuthentication.RedirectFromLoginPage(&lt;span class="st"&gt;&amp;quot;testuser&amp;quot;&lt;/span&gt;, &lt;span class="kwd"&gt;true&lt;/span&gt;); 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;Inside the page_load of the Default.aspx page, I add the following:&amp;nbsp;&lt;pre class="coloredcode"&gt;        &lt;span class="cmt"&gt;// Retrieve the FormsAuthentication Cookie&lt;/span&gt;
        HttpCookie cookie = (HttpCookie)Request.Cookies[FormsAuthentication.FormsCookieName];
        
        &lt;span class="cmt"&gt;// Get the cookie&amp;#39;s payload == Enrypted FormsAuthenticationTicket &lt;/span&gt;
        &lt;span class="kwd"&gt;string&lt;/span&gt; encryptedTicket = cookie.Value;

        &lt;span class="cmt"&gt;// Decrypt the cookie&amp;#39;s payload &lt;/span&gt;
        FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(encryptedTicket);

        Response.Write(&lt;span class="st"&gt;&amp;quot;Ticket Expiry Date: &amp;quot;&lt;/span&gt; + ticket.Expiration.ToLocalTime().ToLongDateString() + ticket.Expiration.ToLocalTime().ToLongTimeString() +&lt;span class="st"&gt;&amp;quot; &amp;lt;br/&amp;gt;&amp;quot;&lt;/span&gt;);
        Response.Write(&lt;span class="st"&gt;&amp;quot;Cookie Expiry Date: &amp;quot;&lt;/span&gt; + cookie.Expires.ToLocalTime().ToLongDateString() + &lt;span class="st"&gt;&amp;quot; &amp;quot;&lt;/span&gt; + cookie.Expires.ToLocalTime().ToLongTimeString() + &lt;span class="st"&gt;&amp;quot; &amp;lt;br/&amp;gt;&amp;quot;&lt;/span&gt;);&lt;/pre&gt;
&lt;p&gt;The output generated is:&lt;/p&gt;
&lt;p&gt;Ticket Expiry Date: Saturday, April 05, 20083:00:44 PM &lt;br /&gt;Cookie Expiry Date: Monday, January 01, 0001 2:00:00 AM&amp;nbsp;&lt;br /&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;If however, you check Reflector, you will notice the following code located inside the private OnAuthenticate method:&amp;nbsp;&lt;pre class="coloredcode"&gt;                        &lt;span class="kwd"&gt;if&lt;/span&gt; (ticket.IsPersistent)
                        {
                            cookie.Expires = ticket.Expiration;
                        }
&lt;/pre&gt;&amp;nbsp; 
&lt;p&gt;&amp;nbsp;&lt;/p&gt;
&lt;p&gt;What can be said now?&lt;/p&gt;
&lt;p&gt;Thanks&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/2002121.aspx</link><pubDate>Mon, 12 Nov 2007 18:25:56 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:2002121</guid><dc:creator>bustell</dc:creator><author>bustell</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/2002121.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=2002121</wfw:commentRss><description>&lt;p&gt;&amp;nbsp;OK, I&amp;#39;ve just spent 2 hours of my life trying to figure out how FormsAuthentication.RedirectFromLoginPage works and I am more confused than when I started.&amp;nbsp; I&amp;#39;ve read all kinds of complicated answers to session time-outs and persistent cookie time-out (which I find interesting... persistent should be persistent).&lt;/p&gt;&lt;p&gt;I am trying to use the Microsoft Login control, but have custom code behind the authenticate event.&lt;/p&gt;&lt;p&gt;The code basically says if the user&amp;#39;s password is good (look up in dateabase), then perform &lt;b&gt;FormsAuthentication.RedirectFromLoginPage(Me.Login1.UserName, Me.Login1.RememberMeSet)&lt;/b&gt;&lt;/p&gt;&lt;p&gt;Unfortunately, if the user click Remember Me, it does really remember them.&amp;nbsp; Very frustrating.&amp;nbsp; I have searched the Internet and can&amp;#39;t come up with an answer / explanation that I understand.&amp;nbsp; Maybe, I&amp;#39;m just being stupid today.&amp;nbsp; I&amp;#39;m not sure.&lt;/p&gt;&lt;p&gt;In one forum, it was mentioned that you can not use RedirectFromLoginPage within the authenticate event because it was too early to set the cookie and that had to be done in the LoggedIn event.&amp;nbsp; So I added e.authenticated = True to my authenticate event and then added the &lt;b&gt;FormsAuthentication.RedirectFromLoginPage(Me.Login1.UserName, Me.Login1.RememberMeSet)&lt;/b&gt; to the LoggedIn event.&amp;nbsp; Still not working. &lt;/p&gt;&lt;p&gt;Does anyone have an example of how to use the login control with your own custom authenticate event?&amp;nbsp; I&amp;#39;m not using Microsoft&amp;#39;s Membership at all.&amp;nbsp; I have my own user/roles/resources tables that I authenticate with.&lt;br /&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1449600.aspx</link><pubDate>Wed, 01 Nov 2006 18:33:06 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1449600</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1449600.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1449600</wfw:commentRss><description>&lt;p&gt;Stefan,&lt;/p&gt;&lt;p&gt;Thanks a lot for the detailed explaination. Is there any specific reason why this behavior changed? I can only&amp;nbsp;think that using web.config&amp;#39;s default value instead of 50 years default will make persistent cookies &amp;quot;more secure&amp;quot;.&lt;/p&gt;&lt;p&gt;Thanks,&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1449571.aspx</link><pubDate>Wed, 01 Nov 2006 18:17:49 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1449571</guid><dc:creator>sschack</dc:creator><author>sschack</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1449571.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1449571</wfw:commentRss><description>&lt;p&gt;In ASP.NET 2.0 you also don&amp;#39;t need to explicitly create a ticket to create a persistent forms auth cookie.&amp;nbsp; However what changed between the two releases is that in ASP.NET 2.0 persistent cookies now use the expiration time defined in the forms authentication configuration section.&amp;nbsp; In ASP.NET 1.0/1.1 persistent forms auth cookies always defaulted to a 50 year expiration.&amp;nbsp; Because of this difference in behavior developers frequently find they need to manually issue persistent forms auth tickets because they need to use a longer expiration time than what is set in config (by default config is set to 30 minutes I believe).&lt;/p&gt;&lt;p&gt;Regarding the guidance about setting only the cookie expiration - developers definitely need to make sure the expiration time used when creating a FormsAuthenticationTicket has the correct time in it.&amp;nbsp; The expiry date on the HttpCookie itself just governs how long the cookie sits in a user&amp;#39;s browser cache.&amp;nbsp; ASP.NET though never trusts that value, and always uses the expiration time from inside of the ticket as the indicator of whether or not the ticket is still considered valid.&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1448769.aspx</link><pubDate>Wed, 01 Nov 2006 04:19:09 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1448769</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1448769.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1448769</wfw:commentRss><description>&lt;p&gt;&lt;em&gt;&amp;gt; If you do want a persistent cookie, then when you manually issue it you need to ensure that the expiration date in the forms auth ticket and the expiry on the coookie itself are using the same duration.&lt;/em&gt; &lt;/p&gt;&lt;p&gt;Thanks for the clarification! But am I right when I say that the behavior has changed in 2.0 because in 1.1 we never used toset FormsAuthenticationTicket explicitly to create persistent cookies. We just used to create a manual cookie, set its expiration time and leave the rest to ASP.NET. &lt;/p&gt;&lt;p&gt;Also, still there are many ASP.NET 2.0 books out there (some of them quite famous) where it is mentioned that to create persistent cookies, one just needs to create a manual cookie and set its expiration time.&amp;nbsp;No mention of setting FormsAuthenticationTicket&amp;#39;s expiration at all!&lt;/p&gt;&lt;p&gt;Let me know your thoughts on this.&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1448376.aspx</link><pubDate>Tue, 31 Oct 2006 20:13:10 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1448376</guid><dc:creator>sschack</dc:creator><author>sschack</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1448376.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1448376</wfw:commentRss><description>&lt;p&gt;I think there is a bit of confusion over the expiration of the forms authentiction ticket, versus the concept of expiration on the cookie itself.&amp;nbsp; The forms authentication feature only looks at the expiration time set on the forms authentication ticket. It never looks at the expiration date set on the cookie itself.&amp;nbsp; The reason is that the forms authentication ticket is encrypted and digitally signed, so its payload can be trusted.&amp;nbsp; However a malicious user can easily forge an Http cookie with a fake expiration date.&amp;nbsp; The only purpose of the cookie&amp;#39;s expiration date in forms authentication is that by explicitly setting an expiry date, the cookie will be persisted in the user&amp;#39;s browser cache.&amp;nbsp; This how &amp;quot;remember me&amp;quot; functionality works - the forms auth ticket is packaged into a cookie and the cookie has an explicit expiration date.&amp;nbsp; That way when a user returns to the site at some future point in time, the browser just automatically sends the forms auth cookie back to the server.&amp;nbsp; However the server decrypts the payload of the cookie, and then looks at the expiration date contained in the payload (not the expiry date of the cookie itself) to determine if the forms auth ticket should still be considered valid.&lt;/p&gt;&lt;p&gt;Unless the intent is to make the cookie stick around on a user&amp;#39;s machine, you don&amp;#39;t need to set the Expiration property of the HttpCookie.&amp;nbsp; If you do want a persistent cookie, then when you manually issue it you need to ensure that the expiration date in the forms auth ticket &lt;strong&gt;and&lt;/strong&gt; the expiry on the coookie itself are using the same duration.&amp;nbsp; Otherwise you can end up in a weird situation where the date in the forms auth ticket and the date on the cookie don&amp;#39;t match.&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1448345.aspx</link><pubDate>Tue, 31 Oct 2006 19:41:24 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1448345</guid><dc:creator>MikeOtown</dc:creator><author>MikeOtown</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1448345.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1448345</wfw:commentRss><description>&lt;p&gt;You are not setting the Expiration property of the cookie.&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1448155.aspx</link><pubDate>Tue, 31 Oct 2006 16:35:03 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1448155</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1448155.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1448155</wfw:commentRss><description>&lt;p&gt;Stefan,&lt;/p&gt;&lt;p&gt;I think I am doing something really stupid because your code above doenst seem to be working as expected (and I am not using Login control). Here is my code in the Login page:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;public&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;partial&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;class&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;Login&lt;/font&gt;&lt;font size="2"&gt; : System.Web.UI.&lt;/font&gt;&lt;font color="#008080" size="2"&gt;Page&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;protected&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; Page_Load(&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;object&lt;/font&gt;&lt;font size="2"&gt; sender, &lt;/font&gt;&lt;font color="#008080" size="2"&gt;EventArgs&lt;/font&gt;&lt;font size="2"&gt; e) &lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; Username = &lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;vivekT&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;; &lt;p&gt;&lt;font color="#0000ff" size="2"&gt;if&lt;/font&gt;&lt;font size="2"&gt; (TextBox1.Text == &lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;a&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;) &lt;p&gt;{&lt;/p&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;//HttpCookie cookie = FormsAuthentication.GetAuthCookie(Username, true); //true is used to create a persistent cookie &lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;// cookie.Expires = DateTime.Now.AddMonths(3); //DOESNT WORK in 2.0 as value is taken from &amp;quot;timeout&amp;quot; attribute in the config file&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;//Manual cookie issuance&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font color="#008080" size="2"&gt;FormsAuthenticationTicket&lt;/font&gt;&lt;font size="2"&gt; authTicket = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthenticationTicket&lt;/font&gt;&lt;font size="2"&gt;(Username, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;, 200); &lt;/font&gt;&lt;font color="#008000" size="2"&gt;//hardcoded 200 minute duration&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; encryptedTicket = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.Encrypt(authTicket); &lt;p&gt;&lt;font color="#008080" size="2"&gt;HttpCookie&lt;/font&gt;&lt;font size="2"&gt; authCookie = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;new&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpCookie&lt;/font&gt;&lt;font size="2"&gt;(&lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.FormsCookieName, encryptedTicket); &lt;p&gt;&lt;font color="#008080" size="2"&gt;HttpContext&lt;/font&gt;&lt;font size="2"&gt;.Current.Response.Cookies.Add(authCookie); &lt;p&gt;Response.Redirect(&lt;font color="#800000" size="2"&gt;&amp;quot;default.aspx&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;); &lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;//Response.Cookies.Add(cookie);&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;//Response.Redirect(FormsAuthentication.GetRedirectUrl(Username, true));//redirect to the originally requested page&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;} &lt;/p&gt;&lt;p&gt;}&lt;/p&gt;&lt;p&gt;}&lt;font color="#008000" size="2"&gt;//end class&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#000000"&gt;Note that if I remove the&amp;nbsp; commented code, and set the web.config timeout value to a large number, then it seems to work (till the timeout value specified).&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;&lt;font color="#008000" size="2"&gt;&lt;font color="#000000"&gt;Please let me know what I am missing here!&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;p&gt;Thanks,&lt;/p&gt;&lt;p&gt;Vivek&lt;font color="#008000" size="2"&gt;&lt;/font&gt;&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1447057.aspx</link><pubDate>Mon, 30 Oct 2006 21:16:13 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1447057</guid><dc:creator>sschack</dc:creator><author>sschack</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1447057.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1447057</wfw:commentRss><description>Yes - but with the workaround noted earlier:&amp;nbsp; remove the cookie in the LoggedIn event of the Login control.&amp;nbsp; I think the control designers felt that with the number of events already on the control, they didn&amp;#39;t want to add another one that specifically dealt with issuing the cookie.</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1447033.aspx</link><pubDate>Mon, 30 Oct 2006 20:54:16 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1447033</guid><dc:creator>MikeOtown</dc:creator><author>MikeOtown</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1447033.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1447033</wfw:commentRss><description>&lt;p&gt;Thanks.&amp;nbsp; I&amp;#39;ll try that.&lt;/p&gt;&lt;p&gt;&amp;nbsp;I thought that you could implement your own authentication by implementing the Login control&amp;#39;s Authenticate event.&amp;nbsp; I guess issuing the cookie isn&amp;#39;t considered part of authentication.&lt;/p&gt;&lt;p&gt;I am setting e.Authenticated = true in the Authenticate event.&lt;/p&gt;&lt;p&gt;So there is no way to tell the Login control to NOT issue a cookie?&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1446956.aspx</link><pubDate>Mon, 30 Oct 2006 20:03:43 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1446956</guid><dc:creator>sschack</dc:creator><author>sschack</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1446956.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1446956</wfw:commentRss><description>&lt;p&gt;From the post I&amp;#39;m not sure if the sample code is being used inside of the Login control or not.&amp;nbsp; I did try the following code in just a plain .aspx page used for login:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Manual cookie issuance&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(txtUserId.Text, false, 200); //hardcoded 200 minute duration&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string encryptedTicket = FormsAuthentication.Encrypt(authTicket);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpContext.Current.Response.Cookies.Add(authCookie);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Redirect(&amp;quot;default.aspx&amp;quot;);&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp;And then in default.aspx writing out the expiration time:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FormsAuthenticationTicket fat = FormsAuthentication.Decrypt(Request.Cookies[&amp;quot;.ASPXAUTH&amp;quot;].Value);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Write(&amp;quot;fat.expires=&amp;quot; + fat.Expiration);&lt;/p&gt;&lt;p&gt;&amp;nbsp;This is returning the correct expiration as set on the login page.&lt;/p&gt;&lt;p&gt;However, if you are attempting to set the cookie from inside of the Login control&amp;#39;s Authenticate event, this event is too early to be setting the cookie manually.&amp;nbsp; The login control event sequence looks like:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Raises the Authenticate event&amp;nbsp;---&amp;gt;&amp;nbsp; Login control sets the cookie&amp;nbsp;with a call to SetAuthCookie --&amp;gt;&amp;nbsp; Raises the LoggedIn event&lt;/p&gt;&lt;p&gt;To manually control the cookie expiration and cookie issuance, put the cookie code in the LoggedIn event.&amp;nbsp; I would recommend first removing the cookie set&amp;nbsp;by the Login control (HttpContext.Current.Response.Cookies.Remove), and then re-issuing the cookie manually.&lt;/p&gt;&lt;p&gt;One other quick note:&amp;nbsp; you should only set the cookie&amp;#39;s expiration property if the user indicated they wanted a persistent cookie.&amp;nbsp; The code shown in the post is always setting the HttpCookie&amp;#39;s expiration date, which has the effect of always making the cookie persistent.&lt;/p&gt;</description></item><item><title>Re: FormsAuthenticationTicket.Expiration value changing</title><link>http://forums.asp.net/thread/1446955.aspx</link><pubDate>Mon, 30 Oct 2006 20:03:39 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1446955</guid><dc:creator>sschack</dc:creator><author>sschack</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1446955.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1446955</wfw:commentRss><description>&lt;p&gt;From the post I&amp;#39;m not sure if the sample code is being used inside of the Login control or not.&amp;nbsp; I did try the following code in just a plain .aspx page used for login:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;//Manual cookie issuance&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FormsAuthenticationTicket authTicket = new FormsAuthenticationTicket(txtUserId.Text, false, 200); //hardcoded 200 minute duration&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; string encryptedTicket = FormsAuthentication.Encrypt(authTicket);&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpCookie authCookie = new HttpCookie(FormsAuthentication.FormsCookieName, encryptedTicket);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; HttpContext.Current.Response.Cookies.Add(authCookie);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Redirect(&amp;quot;default.aspx&amp;quot;);&amp;nbsp; &lt;/p&gt;&lt;p&gt;&amp;nbsp;And then in default.aspx writing out the expiration time:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; FormsAuthenticationTicket fat = FormsAuthentication.Decrypt(Request.Cookies[&amp;quot;.ASPXAUTH&amp;quot;].Value);&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Response.Write(&amp;quot;fat.expires=&amp;quot; + fat.Expiration);&lt;/p&gt;&lt;p&gt;&amp;nbsp;This is returning the correct expiration as set on the login page.&lt;/p&gt;&lt;p&gt;However, if you are attempting to set the cookie from inside of the Login control&amp;#39;s Authenticate event, this event is too early to be setting the cookie manually.&amp;nbsp; The login control event sequence looks like:&lt;/p&gt;&lt;p&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; Raises the Authenticate event&amp;nbsp;---&amp;gt;&amp;nbsp; Login control sets the cookie&amp;nbsp;with a call to SetAuthCookie --&amp;gt;&amp;nbsp; Raises the LoggedIn event&lt;/p&gt;&lt;p&gt;To manually control the cookie expiration and cookie issuance, put the cookie code in the LoggedIn event.&amp;nbsp; I would recommend first removing the cookie set&amp;nbsp;by the Login control (HttpContext.Current.Response.Cookies.Remove), and then re-issuing the cookie manually.&lt;/p&gt;&lt;p&gt;One other quick note:&amp;nbsp; you should only set the cookie&amp;#39;s expiration property if the user indicated they wanted a persistent cookie.&amp;nbsp; The code shown in the post is always setting the HttpCookie&amp;#39;s expiration date, which has the effect of always making the cookie persistent.&lt;/p&gt;</description></item></channel></rss>