<?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: Cookies?</title><link>http://forums.asp.net/thread/1452327.aspx</link><pubDate>Fri, 03 Nov 2006 16:02:58 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1452327</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1452327.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1452327</wfw:commentRss><description>&lt;p&gt;Hello,&lt;/p&gt;
&lt;p&gt;Please mark this post as answered so that fellow contributors can avoid wasting their crucial time opening this post again in order to answer it (as it is still showing unanswered).&lt;/p&gt;
&lt;p&gt;Thanks,&lt;/p&gt;
&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1451254.aspx</link><pubDate>Thu, 02 Nov 2006 18:44:06 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1451254</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1451254.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1451254</wfw:commentRss><description>Thanks Vivek for the update......</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1449619.aspx</link><pubDate>Wed, 01 Nov 2006 18:45:08 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1449619</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1449619.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1449619</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;Few updates: I was again digging this issue in another thread and got to know that there is a way to custom persist cookie in 2.0 by setting a custom FormsAuthenticationTicket expiry.&lt;/p&gt;&lt;p&gt;Check this post:http://forums.asp.net/thread/1448345.aspx&lt;/p&gt;&lt;p&gt;I have also updated my blog: http://geekswithblogs.net/vivek/archive/2006/10/13/93956.aspx&lt;/p&gt;&lt;p&gt;Regards,&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1428067.aspx</link><pubDate>Fri, 13 Oct 2006 15:18:26 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1428067</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1428067.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1428067</wfw:commentRss><description>&lt;font face="courier new"&gt;Yes, Vivek, you have hit the nail on the head. To ensure that the cookie becomes persistent, the &lt;em&gt;&lt;font color="#0000ff"&gt;timeout&lt;/font&gt;&lt;/em&gt; property of the &lt;strong&gt;&lt;font color="#ff0000"&gt;&amp;lt;forms&amp;gt;&lt;/font&gt;&lt;/strong&gt; tag needs to be set in the &lt;strong&gt;web.config&lt;/strong&gt; file; the &lt;em&gt;Expires&lt;/em&gt; property of the &lt;strong&gt;HttpCookie&lt;/strong&gt; object &lt;strong&gt;shouldn&amp;#39;t&lt;/strong&gt; be assigned any value in the ASPX page otherwise the cookie won&amp;#39;t remain persistent.&lt;br /&gt;&lt;br /&gt;Finally I managed to see light at the end of the tunnel....all &lt;strong&gt;THANKS&lt;/strong&gt; to &lt;strong&gt;YOU&lt;/strong&gt;...&lt;/font&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1427611.aspx</link><pubDate>Fri, 13 Oct 2006 06:19:36 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1427611</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1427611.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1427611</wfw:commentRss><description>&lt;p&gt;It is working at my end. Let me elaborate how&amp;nbsp;I am testing the same. &lt;/p&gt;&lt;p&gt;I have created 2 pages, Login and Default. In the Login Page, I have this coding:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;protected&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;br /&gt;{&lt;br /&gt;&lt;/font&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;br /&gt;&lt;/font&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;br /&gt;{&lt;br /&gt;&lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpCookie&lt;/font&gt;&lt;font size="2"&gt; cookie = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.GetAuthCookie(Username, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;); &lt;/font&gt;&lt;font color="#008000" size="2"&gt;//true is used to create a persistent cookie &lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;cookie.Expires = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;DateTime&lt;/font&gt;&lt;font size="2"&gt;.Now.AddMonths(3); &lt;/font&gt;&lt;font color="#008000" size="2"&gt;//DOESN&amp;#39;T WORK&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;Response.Cookies.Add(cookie);&lt;br /&gt;Response.Redirect(&lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.GetRedirectUrl(Username, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;));&lt;/font&gt;&lt;font color="#008000" size="2"&gt;//redirect to the originally requested page&lt;br /&gt;&lt;/font&gt;&lt;font size="2"&gt;} &lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;p&gt;My Web.Config setting:&lt;/p&gt;&lt;font color="#0000ff" size="2"&gt;&lt;p&gt;&amp;lt;&lt;font color="#800000" size="2"&gt;authentication&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;mode&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Forms&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;p&gt;&amp;lt;&lt;font color="#800000" size="2"&gt;forms&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;name&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Test&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;loginUrl&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Login.aspx&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;path&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;/&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;timeout&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;5&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;00000&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;p&gt;&amp;lt;/&lt;font color="#800000" size="2"&gt;forms&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &amp;gt;&lt;p&gt;&amp;lt;/&lt;font color="#800000" size="2"&gt;authentication&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;p&gt;&amp;lt;&lt;font color="#800000" size="2"&gt;authorization&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;gt;&lt;p&gt;&amp;lt;&lt;font color="#800000" size="2"&gt;deny&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;users&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;?&lt;/font&gt;&lt;font size="2"&gt;&amp;quot;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; /&amp;gt;&lt;p&gt;&amp;lt;/&lt;font color="#800000" size="2"&gt;authorization&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;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;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;p&gt;Now even if I change the date on my machine to, let&amp;#39;s say, two days ahead, even then I am able to log in (as my expiry value is 5,00,000 minutes, slightly less than a year). So I think it is working if we assume that the expiry value is taken from the config file and not from the explicit cookie expiry set by us.&lt;/p&gt;&lt;p&gt;Let me know if this is not the case with you.&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1426695.aspx</link><pubDate>Thu, 12 Oct 2006 15:26:49 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1426695</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1426695.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1426695</wfw:commentRss><description>&lt;font face="courier new"&gt;No problem, Vivek if you got busy. After all, everyone&amp;#39;s busy in this world. Still there are nice people like you who take some time out of their busy schedule to help people like me.&lt;br /&gt;&lt;br /&gt;Now getting back to the main topic, I tried setting the timeout in the web.config file to 50000000 but still doesn&amp;#39;t make any difference. The user is forced to login when he opens his browser the very next next day.&lt;br /&gt;&lt;br /&gt;This persistent cookie issue has been really bugging me no end. I guess MS has persistent cookies in theory only &amp;amp; not in practical.......&lt;/font&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1423706.aspx</link><pubDate>Tue, 10 Oct 2006 11:49:19 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1423706</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1423706.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1423706</wfw:commentRss><description>&lt;p&gt;See this post too:&lt;/p&gt;&lt;p&gt;&lt;a href="http://forums.asp.net/thread/1347970.aspx"&gt;http://forums.asp.net/thread/1347970.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1423705.aspx</link><pubDate>Tue, 10 Oct 2006 11:47:44 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1423705</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1423705.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1423705</wfw:commentRss><description>&lt;p&gt;Hi,&lt;/p&gt;&lt;p&gt;I got a bit busy but thanks to your post, I got something to learn myself. I think the MSDN documentation is wrong/confusing when it says that &lt;em&gt;&amp;quot;Persistent cookies do not time out.&amp;quot; (&lt;/em&gt;&lt;a href="http://msdn2.microsoft.com/en-us/library/1d3t3c61.aspx"&gt;http://msdn2.microsoft.com/en-us/library/1d3t3c61.aspx&lt;/a&gt;)&lt;/p&gt;&lt;p&gt;Persistent cookies take the value of the &amp;quot;timeout&amp;quot; attribute in the Web.Config file and to create real persistent cookies you need to make this value very big, like timeout=&amp;quot;5000000&amp;quot;.&lt;/p&gt;&lt;p&gt;See this post for more info: &lt;a href="http://weblogs.asp.net/scottgu/archive/2005/11/08/430011.aspx"&gt;http://weblogs.asp.net/scottgu/archive/2005/11/08/430011.aspx&lt;/a&gt;&lt;/p&gt;&lt;p&gt;Hope this helps,&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1423173.aspx</link><pubDate>Tue, 10 Oct 2006 00:27:23 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1423173</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1423173.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1423173</wfw:commentRss><description>&lt;font face="courier new"&gt;Vivek, you don&amp;#39;t have the answer to my last&amp;nbsp;post in this thread??&lt;/font&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1421584.aspx</link><pubDate>Sat, 07 Oct 2006 19:46:00 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1421584</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1421584.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1421584</wfw:commentRss><description>&lt;font face="courier new"&gt;Vivek, there&amp;#39;s one thing that I don&amp;#39;t understand.&amp;nbsp;When I am setting&amp;nbsp;the second parameter of the &lt;strong&gt;GetAuthCookie&lt;/strong&gt; to &lt;em&gt;True&lt;/em&gt;,&amp;nbsp;why isn&amp;#39;t&amp;nbsp;the cookie becoming persistent. For e.g. consider this code:&lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff"&gt;Dim hCookie As HttpCookie&lt;br /&gt;hCookie = FormsAuthentication.&lt;strong&gt;GetAuthCookie&lt;/strong&gt;(txtUserName.Text, &lt;/font&gt;&lt;font color="#ff69b4"&gt;&lt;strong&gt;True&lt;/strong&gt;&lt;/font&gt;&lt;font color="#0000ff"&gt;)&lt;br /&gt;hCookie.&lt;strong&gt;Expires&lt;/strong&gt; = DateTime.Now.&lt;strong&gt;AddMonths(2)&lt;/strong&gt; &lt;br /&gt;Response.Cookies.Add(hCookie)&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;A cookie gets created today (8th October 2006) after I login. Next I am taken to another ASPX page named &lt;em&gt;Enter.aspx&lt;/em&gt; which says &lt;em&gt;Hello &amp;lt;username&amp;gt;&lt;/em&gt;. I have set this cookie to expire after 2 months i.e. the cookie should expire on 8th December 2006. When I view the cookie in the &lt;em&gt;Temporary Internet Files&lt;/em&gt; folder &amp;amp; just click this cookie, the expiry date, as expected, is set to 8th December 2006.&lt;br /&gt;&lt;br /&gt;Note that if a user tries to navigate to &lt;em&gt;Enter.aspx&lt;/em&gt; without logging in, he is directed to the login page which has the code snippet shown above.&lt;br /&gt;&lt;br /&gt;I close the browser window I used to login &amp;amp; open a new browser window. When I navigate to &lt;em&gt;Enter.aspx&lt;/em&gt;, I am shown the &lt;em&gt;Hello &amp;lt;username&amp;gt;&lt;/em&gt; message. Irrespective of the number of times I open a new browser window &lt;strong&gt;today&lt;/strong&gt; &amp;amp; navigate to &lt;em&gt;Enter.aspx&lt;/em&gt;, I am always shown the message &lt;em&gt;Hello &amp;lt;username&amp;gt;&lt;/em&gt;. At no time have I logged out today. OK.....fine....no problem till here. &lt;br /&gt;&lt;br /&gt;But when I navigate to &lt;em&gt;Enter.aspx&lt;/em&gt; tomorrow (i.e. 9th October 2006) &amp;amp; try to navigate to &lt;em&gt;Enter.aspx&lt;/em&gt;, I am redirected to the login page to login. Why? Using the &lt;strong&gt;GetAuthCookie&lt;/strong&gt; method of the &lt;strong&gt;FormsAuthentication&lt;/strong&gt; object, I have created a &lt;strong&gt;&lt;font color="#ff0000"&gt;persistent cookie&lt;/font&gt;&lt;/strong&gt; by setting the second parameter of the &lt;strong&gt;GetAuthCookie&lt;/strong&gt; to &lt;em&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;True&lt;/strong&gt;&lt;/font&gt;&lt;/em&gt;. Even the cookie in the &lt;em&gt;Temporary Internet Files&lt;/em&gt; folder says that it is set to expire on 8th December 2006.&lt;br /&gt;&lt;br /&gt;So why am I being told to login again when I try to navigate to &lt;em&gt;Enter.aspx&lt;/em&gt; on 9th October 2006? Why isn&amp;#39;t the cookie persisting till 8th December 2006?&lt;/font&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1420743.aspx</link><pubDate>Fri, 06 Oct 2006 15:23:50 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1420743</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1420743.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1420743</wfw:commentRss><description>&lt;font face="courier new"&gt;That&amp;#39;s &lt;strong&gt;EXACTLY&lt;/strong&gt; what I wanted to know - how to use the encrypted &lt;strong&gt;FormsAuthenticationTicket&lt;/strong&gt; to retrieve the username. Thanks a lot, Vivek, for all the help you have extended towards me.&lt;br /&gt;&lt;br /&gt;I am sorry....I guess I overlooked that &lt;strong&gt;Response.Redirect&lt;/strong&gt; line in your blog....&lt;/font&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1416871.aspx</link><pubDate>Tue, 03 Oct 2006 12:59:01 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1416871</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1416871.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1416871</wfw:commentRss><description>&lt;p&gt;GethAuthCookie puts the user name in an object of FormsAuthenticationTicket and later calls the FormsAuthentication.Encrypt(ticket) method. You can access this value as:&lt;/p&gt;&lt;font size="2"&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;br /&gt;{&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpCookie&lt;/font&gt;&lt;font size="2"&gt; loginCookie = Request.Cookies[&lt;/font&gt;&lt;font color="#800000" size="2"&gt;&amp;quot;Test&amp;quot;&lt;/font&gt;&lt;font size="2"&gt;];&amp;nbsp; //&amp;quot;Test&amp;quot;&amp;nbsp;is&amp;nbsp;the cookie name specified in&amp;nbsp;the config file.&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthenticationTicket&lt;/font&gt;&lt;font size="2"&gt; t = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.Decrypt(loginCookie.Value);&lt;br /&gt;&amp;nbsp;&amp;nbsp; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; userName = t.Name; //this is the userName stored while cookie was created as &lt;font color="#008080" size="2"&gt;HttpCookie&lt;/font&gt;&lt;font size="2"&gt; cookie = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.GetAuthCookie(Username, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;);&lt;/font&gt;&lt;br /&gt;}&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;p&gt;But use this code only when needed since many times using the Session is more helpful as cookies can be tampered at client side. In case you need persistent cookies, then this is ok. But it is recommended that you expire cookies as soon as possible (besides keeping Session timeouts as low as possible).&lt;/p&gt;&lt;p&gt;Also, RedirectFormLoginPage uses Response.Redirect() only. It seems you did not read my blog carefully enough :-).&lt;/p&gt;&lt;p&gt;Hope this helps,&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1415352.aspx</link><pubDate>Sun, 01 Oct 2006 15:16:07 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1415352</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1415352.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1415352</wfw:commentRss><description>&lt;font face="Courier New"&gt;If the encrypted ticket information can&amp;#39;t be used to retrieve the username, then what for is&amp;nbsp;username passed as the first parameter to the &lt;strong&gt;GetAuthCookie&lt;/strong&gt;, &lt;strong&gt;SetAuthCookie&lt;/strong&gt; &amp;amp;&amp;nbsp;&lt;strong&gt;RedirectFromLoginPage&lt;/strong&gt; methods of the &lt;strong&gt;FormsAuthentication&lt;/strong&gt; object? How does an ASP.NET developer make use of the encrypted ticket information? Can&amp;#39;t the encrypted ticket information be used to ensure that a user isn&amp;#39;t forced to login again &amp;amp; again once the FormsAuthentication cookie gets created in the user&amp;#39;s local m/c&amp;nbsp;until the cookie is set to expire?&lt;br /&gt;&lt;br /&gt;Also why&amp;nbsp;use &lt;strong&gt;Response.Redirect&lt;/strong&gt; (which involves 2 round trips from the server to the client) when the &lt;strong&gt;RedirectFromLoginPage&lt;/strong&gt; method can be used?&lt;/font&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1415011.aspx</link><pubDate>Sat, 30 Sep 2006 19:37:57 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1415011</guid><dc:creator>vivek_iit</dc:creator><author>vivek_iit</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1415011.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1415011</wfw:commentRss><description>&lt;p&gt;Hello,&lt;/p&gt;&lt;p&gt;You should not overwrite the cookie&amp;#39;s Value as it stores the encrypted ticket information in it (which you have over written with the username value).&lt;/p&gt;&lt;p&gt;Also, you do not need to use &lt;font color="#0000ff" face="Courier New"&gt;FormsAuthentication.&lt;strong&gt;RedirectFromLoginPage&lt;/strong&gt;(txtUserName.Text, True) &lt;font color="#000000" face="Arial"&gt;when you are setting the cookie yourself. In your case, the cookie will not expire as the page has re-directed using the cookie set in the above method. Use like:&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;&lt;font color="#008080" size="2"&gt;&lt;p&gt;HttpCookie&lt;font size="2"&gt; cookie = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.GetAuthCookie(Username, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;); &lt;/font&gt;&lt;font color="#008000" size="2"&gt;//true is used to create a persistent cookie&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;&amp;nbsp;&lt;/p&gt;&lt;p&gt;cookie.Expires = &lt;font color="#008080" size="2"&gt;DateTime&lt;/font&gt;&lt;font size="2"&gt;.Now.AddSeconds(10); &lt;/font&gt;&lt;font color="#008000" size="2"&gt;//this will expire after 3 months&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;p&gt;Response.Cookies.Add(cookie);&lt;/p&gt;&lt;p&gt;Response.Redirect(&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.GetRedirectUrl(Username, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;true&lt;/font&gt;&lt;font size="2"&gt;));&lt;/font&gt;&lt;font color="#008000" size="2"&gt;//redirect to the originally requested page&lt;/font&gt;&lt;/p&gt;&lt;/font&gt;&lt;p&gt;If you want to get the username, store it in session or create another cookie, but do not tamper with the values of the Authentication cookies.&lt;/p&gt;&lt;p&gt;&amp;nbsp;Hope this helps,&lt;/p&gt;&lt;p&gt;Vivek&lt;/p&gt;</description></item><item><title>Re: Cookies?</title><link>http://forums.asp.net/thread/1413843.aspx</link><pubDate>Fri, 29 Sep 2006 08:53:35 GMT</pubDate><guid isPermaLink="false">4c671506-2930-414c-a40b-8bf57ded5924:1413843</guid><dc:creator>RN5A</dc:creator><author>RN5A</author><slash:comments>0</slash:comments><comments>http://forums.asp.net/thread/1413843.aspx</comments><wfw:commentRss>http://forums.asp.net/commentrss.aspx?SectionID=25&amp;PostID=1413843</wfw:commentRss><description>&lt;font face="Courier New"&gt;Thanks, Vivek, your aticle has indeed turned out to be very useful but&amp;nbsp;I have encountered&amp;nbsp;another problem.&amp;nbsp;Keeping the &lt;font color="#ff0f9f"&gt;web.config&lt;/font&gt; file shown in post #1 as it is, I am adding the following setting so that any user can access &lt;em&gt;HomePage.aspx&lt;/em&gt;:&lt;br /&gt;&lt;br /&gt;&lt;/font&gt;&lt;font face="Courier New"&gt;&lt;font color="#ff0f9f"&gt;&amp;lt;location path=&amp;quot;HomePage.aspx&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;system.web&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &amp;lt;authorization&amp;gt;&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;lt;allow users=&amp;quot;*&amp;quot;/&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/authorization&amp;gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;lt;/system.web&amp;gt;&lt;br /&gt;&amp;lt;/location&amp;gt;&lt;br /&gt;&lt;/font&gt;&lt;br /&gt;&lt;font color="#000000"&gt;Suppose a user comes to &lt;em&gt;HomePage.aspx&lt;/em&gt;. From the home page, he tries to navigate to another ASPX page, say, &lt;em&gt;MyPage.aspx&lt;/em&gt; by clicking a link in the home page. But the web.config file redirects the user to &lt;em&gt;Login.aspx.&lt;/em&gt;&amp;nbsp;Assuming that the user has been validated successfully, he is then directed to &lt;em&gt;MyPage.aspx&lt;/em&gt;. Also assume that the username of the user is &lt;em&gt;bobby&lt;/em&gt;. When this user finally goes to &lt;em&gt;MyPage.aspx&lt;/em&gt;, I want to display a welcome message to him with his username i.e. &lt;em&gt;MyPage.aspx&lt;/em&gt; should display &lt;em&gt;Welcome bobby&lt;/em&gt;.&amp;nbsp;To get the username in &lt;em&gt;MyPage&lt;/em&gt;.aspx&lt;em&gt;, &lt;/em&gt;I am using the &lt;em&gt;Name&lt;/em&gt; &amp;amp; &lt;em&gt;Value&lt;/em&gt; properties of the &lt;strong&gt;&lt;em&gt;HttpCookie&lt;/em&gt;&lt;/strong&gt; object in &lt;em&gt;Login.aspx&lt;/em&gt;. This is the code in &lt;em&gt;Login.aspx&lt;/em&gt;:&lt;/font&gt;&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font color="#0000ff" face="Courier New"&gt;Sub LoginUser(obj As Object, ea As EventArgs) &lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&lt;/font&gt;&lt;font color="#d3d3d3" face="Courier New"&gt; &amp;#39;after successful login&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff" face="Courier New"&gt;Dim hCookie As &lt;strong&gt;HttpCookie&lt;/strong&gt;&lt;br /&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; FormsAuthentication.&lt;strong&gt;RedirectFromLoginPage&lt;/strong&gt;(txtUserName.Text, True)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; hCookie = FormsAuthentication.&lt;strong&gt;GetAuthCookie&lt;/strong&gt;(txtUserName.Text, True)&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#ff0000" face="Courier New"&gt;hCookie.Name = &amp;quot;MyCookie&amp;quot;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; hCookie.Value = txtUserName.Text&lt;/font&gt;&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;font color="#0000ff" face="Courier New"&gt;hCookie.&lt;strong&gt;Expires&lt;/strong&gt; = DateTime.Now.AddMinutes(2)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;Response.Cookies.Add(hCookie) &lt;br /&gt;End Sub&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;&lt;font face="Courier New"&gt;This is the simple code in &lt;em&gt;MyPage.aspx&lt;/em&gt;:&lt;br /&gt;&lt;br /&gt;&lt;font color="#ff1493"&gt;Sub Page_Load(ByVal obj As Object, ByVal ea As EventArgs)&lt;br /&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp; lblMessage.Text = &amp;quot;Welcome &amp;quot; &amp;amp; Request.Cookies(&amp;quot;MyCookie&amp;quot;).Value&lt;br /&gt;End Sub&lt;/font&gt;&lt;br /&gt;&lt;br /&gt;When this user finally comes to &lt;em&gt;MyPage.aspx&lt;/em&gt;, he is shown the message&lt;br /&gt;&lt;br /&gt;Welcome bobby&lt;br /&gt;&lt;br /&gt;Note that in &lt;em&gt;Login.aspx&lt;/em&gt;, I have set the cookie to expire after 2 minutes which means that the user sees the welcome message along with his username if he closes the browser he used to login &amp;amp; opens a new browser within the next 2 minutes. But when I go to the Temporary Internet Files folder &amp;amp; click the cookie, I find that the cookie has been set to expire after 30 minutes though I have set it to expire after 2 minutes. Why so?&lt;br /&gt;&lt;br /&gt;What I found is if I get rid of the 2 red lines in &lt;em&gt;Login.aspx&lt;/em&gt;, then the cookie gets set to expire after 2 minutes in the Temporary Internet Files folder but if I get rid of the 2 red lines in &lt;em&gt;Login.aspx&lt;/em&gt;, how do I retrieve the username of the user in &lt;em&gt;MyPage.aspx&lt;/em&gt;?&lt;/font&gt; &lt;br /&gt;&lt;br /&gt;&lt;font face="Courier New"&gt;Also is there any way by which &lt;em&gt;MyPage.aspx&lt;/em&gt; can access the first parameter&amp;nbsp;of the methods &lt;strong&gt;RedirectFromLoginPage&lt;/strong&gt; &amp;amp; &lt;strong&gt;GetAuthCookie&lt;/strong&gt; (which is &lt;em&gt;txtUserName.Text&lt;/em&gt;)? If no, then what&amp;#39;s the use of the first parameter in the methods &lt;strong&gt;RedirectFromLoginPage&lt;/strong&gt; &amp;amp; &lt;strong&gt;GetAuthCookie&lt;/strong&gt;?&lt;/font&gt;</description></item></channel></rss>