<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Seree Woradechjamroen &#187; authentication</title>
	<atom:link href="http://www.iamseree.com/tag/authentication/feed" rel="self" type="application/rss+xml" />
	<link>http://www.iamseree.com</link>
	<description>Keep learning everyday, willing to win and take action</description>
	<lastBuildDate>Mon, 02 Jan 2012 19:00:27 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.1</generator>
		<item>
		<title>Real world ASP.NET authentication</title>
		<link>http://www.iamseree.com/application-development/real-world-aspnet-authentication</link>
		<comments>http://www.iamseree.com/application-development/real-world-aspnet-authentication#comments</comments>
		<pubDate>Thu, 02 Aug 2007 15:49:32 +0000</pubDate>
		<dc:creator>Seree</dc:creator>
				<category><![CDATA[Application Development]]></category>
		<category><![CDATA[.net]]></category>
		<category><![CDATA[.net authentication]]></category>
		<category><![CDATA[asp.net]]></category>
		<category><![CDATA[authentication]]></category>
		<category><![CDATA[cookies authentication]]></category>
		<category><![CDATA[form based authentication]]></category>

		<guid isPermaLink="false">http://www.iamseree.com/?p=14</guid>
		<description><![CDATA[<p>Hello everyone,</p> <p>I&#8217;m here to say that most of ASP.NET books on the market didn&#8217;t provide you the effective way to use authentication cookies.</p> <p>Assume that when you&#8217;re working with form-based authentication. (Setting in web.config) When we do some manual authentication method, we imports System.Web.Security and using FormsAuthentication.RedirectFromLoginPage(&#8220;userName&#8221;, false). The ASP.NET authentication engine will automatically [...]]]></description>
			<content:encoded><![CDATA[<p>Hello everyone,</p>
<p>I&#8217;m here to say that most of ASP.NET books on the market didn&#8217;t provide you the effective way to use authentication cookies.</p>
<p>Assume that when you&#8217;re working with form-based authentication. (Setting in web.config) When we do some manual authentication method, we imports System.Web.Security and using FormsAuthentication.RedirectFromLoginPage(&#8220;userName&#8221;, false). The ASP.NET authentication engine will automatically create a cookie to persist authenticate status. This cookies was used to identify the user have been signed in or not. So, when we want to store some of user&#8217;s profile. How do we do it?</p>
<p>We can coding to create new cookie object to store those profile but we already known that ASP.NET authentication engine already created the cookie when signed in. The question should be &#8220;How do we access this cookie? Is it possible?&#8221;.</p>
<p>Certainly, you can do it. Please review the following code.</p>
<p>In your login button&#8217;s click event.</p>
<blockquote><p>if(AuthSucceeded){<span id="more-14"></span></p>
<p>HttpCookie cookie = FormsAuthentication.GetAuthCookie(txtLoginName.Text, false);</p>
<p>FormsAuthenticationTicket ticket = FormsAuthentication.Decrypt(cookie.Value);</p>
<p>FormsAuthenticationTicket newticket = new FormsAuthenticationTicket(ticket.Version, ticket.Name, ticket.IssueDate, ticket.Expiration, ticket.IsPersistent, &#8220;Secret|Role|CustomVar1&#8243;, ticket.CookiePath);</p>
<p>cookie.Value = FormsAuthentication.Encrypt(newticket);</p>
<p>Context.Response.Cookies.Set(cookie);</p>
<p>}</p></blockquote>
<p>The above code was used to create an authenticated cookie with custom profile/data. (&#8220;Secret|Role|CustomVar1&#8243;)</p>
<p>When we need to extract the custom profile/data, we do with the following code.</p>
<blockquote><p>FormsIdentity ident = (FormsIdentity)User.Identity;string strCustomData = ident.Ticket.UserData.ToString();</p></blockquote>
<p>With this method, we don&#8217;t need any separated cookies to store the authenticated user&#8217;s profile anymore.</p>
<p><strong>Hope this help you get step ahead on your ASP.NET skill.</strong></p>
<p><!--adsense--></p>
<div align="left" style="float: ; padding: 5px 5px 0px 0px;"><a name="fb_share" type="button" share_url="http://www.iamseree.com/application-development/real-world-aspnet-authentication"></a></div>]]></content:encoded>
			<wfw:commentRss>http://www.iamseree.com/application-development/real-world-aspnet-authentication/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

