<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/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>Care, Share and Grow! : Forms Authentication</title><link>http://blogs.msdn.com/saurabh_singh/archive/tags/Forms+Authentication/default.aspx</link><description>Tags: Forms Authentication</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Getting little deeper: How ASP.Net Forms based authentication flows...</title><link>http://blogs.msdn.com/saurabh_singh/archive/2007/04/19/getting-little-deeper-how-asp-net-forms-based-authentication-flows.aspx</link><pubDate>Thu, 19 Apr 2007 13:42:00 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:2190044</guid><dc:creator>Saurabh Singh</dc:creator><slash:comments>6</slash:comments><comments>http://blogs.msdn.com/saurabh_singh/comments/2190044.aspx</comments><wfw:commentRss>http://blogs.msdn.com/saurabh_singh/commentrss.aspx?PostID=2190044</wfw:commentRss><wfw:comment>http://blogs.msdn.com/saurabh_singh/rsscomments.aspx?PostID=2190044</wfw:comment><description>&lt;p&gt;I have been recently supporting Asp.Net apart from IIS&amp;nbsp;in the role of a&amp;nbsp;Microsoft GTSC Developer Support Engineer.&lt;/p&gt; &lt;p&gt;I&amp;nbsp;had been a programmer earlier, but had more expertise on C, C++ and other unmanaged non-web stuffs. I am new to Web technology as per the programming background is concerned. I started working on specific topics which we regularly encounter in our daily support calls, and found Forms based authentication to be one of the most interesting and&amp;nbsp;challenging topics to troubleshoot.&lt;/p&gt; &lt;p&gt;Here i take a moment to dig deep in explaining the forms authentication. The below analysis helped me in a big way to understand how the HTTP traffice flows and what are the headers we need to concentrate upon.&lt;/p&gt; &lt;p&gt;I will show&amp;nbsp;a series of Web request/response flows when a user tries to access a website which is configured for Forms based authentication. &lt;/p&gt; &lt;p&gt;Let's say, a user requests for accessing a protected web page on a site.&lt;/p&gt; &lt;p&gt;So accordingly he should be redirected to a login page where he needs to enter the credentials and once validated against a user data store, he should be taken to the requested page.&lt;/p&gt; &lt;p&gt;For our example&amp;nbsp;I have written a very generic&amp;nbsp;code as shown below:&lt;/p&gt; &lt;p mce_keep="true"&gt;&amp;nbsp;&lt;/p&gt; &lt;p&gt;&lt;em&gt;Default.aspx&lt;/em&gt; page, which&amp;nbsp;checks whether user is authenticated or not. If yes, then it displays&amp;nbsp;webpage content. If user is not authenticated he will be redirected to the login page. You can copy paste and try it for yourself.&lt;/p&gt; &lt;p&gt;&lt;u&gt;Default.aspx&lt;/u&gt;&lt;/p&gt; &lt;p&gt;&amp;lt;%@Page Language="VB"&amp;nbsp;%&amp;gt;&lt;br&gt;&amp;lt;%@Import Namespace="System.Web.Security" %&amp;gt; &lt;/p&gt; &lt;p&gt;&amp;lt;script language="vb" runat="server"&amp;gt;  &lt;p&gt;Sub SignOut(objSender As Object, objArgs As EventArgs)&lt;br&gt;'delete the users auth cookie and sign out&lt;br&gt;FormsAuthentication.SignOut()&lt;br&gt;'redirect the user to their referring page&lt;br&gt;Response.Redirect(Request.UrlReferrer.ToString())&lt;br&gt;End Sub  &lt;p&gt;Sub Page_Load()&lt;br&gt;'verify authentication&lt;br&gt;If User.Identity.IsAuthenticated Then&lt;br&gt;'display Credential information&lt;br&gt;displayCredentials.InnerHtml = "Current User : &amp;lt;b&amp;gt;" &amp;amp; User.Identity.Name &amp;amp; "&amp;lt;/b&amp;gt;" &amp;amp; _&lt;br&gt;"&amp;lt;br&amp;gt;&amp;lt;br&amp;gt;Authentication Used : &amp;lt;b&amp;gt;" &amp;amp; User.Identity.AuthenticationType &amp;amp; "&amp;lt;/b&amp;gt;"&lt;br&gt;session("Name") = User.Identity.Name&lt;br&gt;Else&lt;br&gt;'Display Error Message&lt;br&gt;displayCredentials.InnerHtml = "Sorry, you have not been authenticated."&lt;br&gt;End If&lt;br&gt;End Sub  &lt;p&gt;&amp;lt;/script&amp;gt;  &lt;p&gt;&amp;lt;html&amp;gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;Forms Authentication&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;/head&amp;gt;&lt;br&gt;&amp;lt;body bgcolor="#FFFFFF" text="#000000"&amp;gt;&lt;br&gt;&amp;lt;span class="Header"&amp;gt;Forms Based Authentication using standard method&amp;lt;/span&amp;gt;&lt;br&gt;&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;div id="displayCredentials" runat="server" /&amp;gt;&lt;br&gt;&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;form runat="server" method="POST"&amp;gt;&lt;br&gt;&amp;lt;asp:TextBox id="TextBox1" runat="server" /&amp;gt;&lt;br&gt;&amp;lt;asp:Button id="cmdSignOut" text="Sign Out" runat="server" onClick="SignOut" /&amp;gt;&lt;br&gt;&amp;lt;asp:Button id="Button1" runat="server" text="Submit"/&amp;gt;&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;asp:TextBox id="TextBox2" runat="server" /&amp;gt;&lt;br&gt;&amp;lt;/form&amp;gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;  &lt;p&gt;&lt;u&gt;Login.aspx&lt;/u&gt;  &lt;p&gt;&amp;lt;%@Page Language="VB" %&amp;gt;&lt;br&gt;&amp;lt;%@Import Namespace="System.Web.Security" %&amp;gt;  &lt;p&gt;&amp;lt;script language="VB" runat="server"&amp;gt;  &lt;p&gt;Sub ProcessLogin(objSender As Object, objArgs As EventArgs)  &lt;p&gt;If FormsAuthentication.Authenticate(txtUser.Text, txtPassword.Text) Then&lt;br&gt;FormsAuthentication.RedirectFromLoginPage(txtUser.Text, chkPersistLogin.Checked)&lt;br&gt;Else&lt;br&gt;ErrorMessage.InnerHtml = "&amp;lt;b&amp;gt;Something went wrong...&amp;lt;/b&amp;gt; please re-enter your credentials..."&lt;br&gt;End If  &lt;p&gt;End Sub  &lt;p&gt;&amp;lt;/script&amp;gt;  &lt;p&gt;&amp;lt;html&amp;gt;&lt;br&gt;&amp;lt;head&amp;gt;&lt;br&gt;&amp;lt;title&amp;gt;Standard Forms Authentication Login Form&amp;lt;/title&amp;gt;&lt;br&gt;&amp;lt;/head&amp;gt;  &lt;p&gt;&amp;lt;body bgcolor="#FFFFFF" text="#000000"&amp;gt;&lt;br&gt;&amp;lt;form runat="server"&amp;gt;&lt;br&gt;&amp;lt;table width="400" border="0" cellspacing="0" cellpadding="0"&amp;gt;&lt;br&gt;&amp;lt;tr&amp;gt;&lt;br&gt;&amp;lt;td width="80"&amp;gt;Username : &amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td width="10"&amp;gt; &amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td&amp;gt;&amp;lt;asp:TextBox Id="txtUser" width="150" runat="server"/&amp;gt;&amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;/tr&amp;gt;&lt;br&gt;&amp;lt;tr&amp;gt;&lt;br&gt;&amp;lt;td&amp;gt;Password : &amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td width="10"&amp;gt; &amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td&amp;gt;&amp;lt;asp:TextBox Id="txtPassword" width="150" TextMode="Password" runat="server"/&amp;gt;&amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;/tr&amp;gt;&lt;br&gt;&amp;lt;tr&amp;gt;&lt;br&gt;&amp;lt;tr&amp;gt;&lt;br&gt;&amp;lt;td&amp;gt;&amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td width="10"&amp;gt; &amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td&amp;gt;&amp;lt;asp:CheckBox id="chkPersistLogin" runat="server" /&amp;gt;Remember my credentials&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;/tr&amp;gt;&lt;br&gt;&amp;lt;tr&amp;gt;&lt;br&gt;&amp;lt;td&amp;gt; &amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td width="10"&amp;gt; &amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;td&amp;gt;&amp;lt;asp:Button Id="cmdLogin" OnClick="ProcessLogin" Text="Login" runat="server" /&amp;gt;&amp;lt;/td&amp;gt;&lt;br&gt;&amp;lt;/tr&amp;gt;&lt;br&gt;&amp;lt;/table&amp;gt;&lt;br&gt;&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;br&amp;gt;&lt;br&gt;&amp;lt;div id="ErrorMessage" runat="server" /&amp;gt;&lt;br&gt;&amp;lt;/form&amp;gt;&lt;br&gt;&amp;lt;/body&amp;gt;&lt;br&gt;&amp;lt;/html&amp;gt;  &lt;p&gt;For demonstration purpose I have added users to the web.config files instead of using any other store like a SQL server or Active Directory store for storing user's credentials.  &lt;p&gt;Here is the &lt;u&gt;web.config&lt;/u&gt; file section of our interest:  &lt;p&gt;&amp;lt;configuration&amp;gt;&lt;br&gt;&amp;lt;system.web&amp;gt;&lt;br&gt;&amp;lt;customErrors mode="Off"/&amp;gt; &lt;/p&gt; &lt;p&gt;&amp;lt;authentication mode="&lt;strong&gt;Forms&lt;/strong&gt;"&amp;gt;&lt;br&gt;&amp;lt;forms name="FormsAuthCookie" path="/" loginUrl="login.aspx" protection="All" &lt;strong&gt;timeout="1" slidingExpiration="false"&lt;/strong&gt;&amp;gt;&lt;br&gt;&amp;lt;credentials passwordFormat="Clear"&amp;gt;&lt;br&gt;&lt;strong&gt;&amp;lt;user name="john" password="test1" /&amp;gt;&lt;br&gt;&amp;lt;user name="Randy" password="test2" /&amp;gt;&lt;/strong&gt;&lt;/p&gt; &lt;p&gt;&lt;strong&gt;....&lt;br&gt;&lt;/strong&gt;&amp;lt;/credentials&amp;gt;&lt;br&gt;&amp;lt;/forms&amp;gt;&lt;br&gt;&amp;lt;/authentication&amp;gt; &lt;/p&gt; &lt;p&gt;&amp;lt;authorization&amp;gt;&lt;br&gt;&lt;strong&gt;&amp;lt;deny users="?" /&amp;gt;&lt;/strong&gt;&lt;br&gt;&amp;lt;/authorization&amp;gt; &lt;/p&gt; &lt;p&gt;&amp;lt;sessionState &lt;br&gt;mode="InProc" &lt;br&gt;stateConnectionString="tcpip=127.0.0.1:42424" &lt;br&gt;stateNetworkTimeout="10" &lt;br&gt;sqlConnectionString="data source=127.0.0.1;Integrated Security=SSPI" &lt;br&gt;sqlCommandTimeout="30" &lt;br&gt;cookieless="UseCookies" &lt;br&gt;cookieName="AppSessionCookie" &lt;br&gt;&lt;strong&gt;timeout="2"&lt;/strong&gt;&amp;gt; &lt;br&gt;&amp;lt;/sessionState&amp;gt;  &lt;p&gt;&amp;lt;/system.web&amp;gt;&lt;br&gt;&amp;lt;/configuration&amp;gt;  &lt;p&gt;Here if you notice,&amp;nbsp;I have set the SlidingExpiration to False, which mean users will be logged out after a specific interval from the time they logged in, in our case it is set to timeout= "1" min.  &lt;p&gt;If you want you can encrypt the user's credentials using hash algorithm like SHA1 etc. but it is not in the agenda of this blog.  &lt;p&gt;I won't go much&amp;nbsp;into the details about the settings here since you will get tonnes of articles on implementing forms based authentication on the net.  &lt;p&gt;I will basically show you how Request/Response flow occurs between the server and the client during Forms based authentication.  &lt;p&gt;&lt;em&gt;&lt;u&gt;Here we go:&lt;/u&gt;&lt;/em&gt;  &lt;p&gt;Step 1: Client sends a web request for the Default.aspx (&lt;em&gt;or any page of your choice in the website except the login page; who would prefer to go through a login page to access&amp;nbsp;one's desired webpage if given a chance :-)&lt;/em&gt;)&amp;nbsp;page to the&amp;nbsp;server.  &lt;p&gt;[You can focus only on the bold headers for our purpose]  &lt;p&gt;You type in the following url in the IE browser, &lt;a href="http://saurabsi-sec/FormsAuthentication/default.aspx" mce_href="http://saurabsi-sec/FormsAuthentication/default.aspx"&gt;http://saurabsi-sec/FormsAuthentication/default.aspx&lt;/a&gt; and hit &lt;font color="#ff0000"&gt;&lt;strong&gt;Go!&lt;/strong&gt;&lt;/font&gt;  &lt;p&gt;&lt;u&gt;&lt;em&gt;From Client&lt;/em&gt;&lt;/u&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;GET /FormsAuthentication/default.aspx HTTP/1.1&lt;/strong&gt;&lt;br&gt;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*&lt;br&gt;Accept-Language: en-us&lt;br&gt;UA-CPU: x86&lt;br&gt;Accept-Encoding: gzip, deflate&lt;br&gt;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 1.1.4322; InfoPath.2)&lt;br&gt;Host: saurabsi-sec&lt;br&gt;Proxy-Connection: Keep-Alive&lt;/font&gt;&lt;/p&gt; &lt;p&gt;&lt;u&gt;&lt;em&gt;&lt;font color="#800040"&gt;&lt;/font&gt;&lt;/em&gt;&lt;/u&gt; &lt;p&gt;Step 2: Server sends a response back to the Client with a status 302 Object Moved:  &lt;p&gt;&lt;u&gt;&lt;em&gt;From Server&lt;/em&gt;&lt;/u&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;HTTP/1.1 302 Found&lt;/strong&gt;&lt;br&gt;Date: Thu, 19 Apr 2007 07:11:43 GMT&lt;br&gt;Server: Microsoft-IIS/6.0&lt;br&gt;X-Powered-By: ASP.NET&lt;br&gt;MicrosoftOfficeWebServer: 5.0_Pub&lt;br&gt;X-AspNet-Version: 2.0.50727&lt;br&gt;&lt;strong&gt;Location: /FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx&lt;/strong&gt;&lt;br&gt;Cache-Control: private&lt;br&gt;Content-Type: text/html; charset=utf-8&lt;br&gt;Content-Length: 196&lt;/font&gt; &lt;/p&gt; &lt;p&gt;Notice the Response status code and the Location in the response header. Server says to the client that it (client)&amp;nbsp;needs to resend a request to the url mentioned in the Location header.  &lt;p&gt;Step 3: Client&amp;nbsp;then resends&amp;nbsp;a new&amp;nbsp;request&amp;nbsp;for a&amp;nbsp;/FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx&lt;br&gt;page. Now here since the client has to first get to the login.aspx page it will send a GET request first and not a POST request. Remember the first request to any site will be a GET and not POST.  &lt;p&gt;&lt;u&gt;&lt;em&gt;From Client&lt;/em&gt;&lt;/u&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;GET /FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx HTTP/1.1&lt;/strong&gt;&lt;br&gt;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*&lt;br&gt;Accept-Language: en-us&lt;br&gt;UA-CPU: x86&lt;br&gt;Accept-Encoding: gzip, deflate&lt;br&gt;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 1.1.4322; InfoPath.2)&lt;br&gt;Host: saurabsi-sec&lt;br&gt;Proxy-Connection: Keep-Alive&lt;/font&gt; &lt;/p&gt; &lt;p&gt;Remember the querystring &lt;em&gt;&lt;strong&gt;ReturnUrl&lt;/strong&gt;&lt;/em&gt; shows the original requested page. Client is supposed to send a request later after authentication is done to this&amp;nbsp;page. This is the way how the request/response maintains a track of the requested page throughout the transaction.  &lt;p&gt;Step 4: Server sends back the requested login.aspx page with a 200 OK Response.  &lt;p&gt;&lt;em&gt;&lt;u&gt;From Server&lt;/u&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;HTTP/1.1 200 OK&lt;/strong&gt;&lt;br&gt;Date: Thu, 19 Apr 2007 07:11:43 GMT&lt;br&gt;Server: Microsoft-IIS/6.0&lt;br&gt;X-Powered-By: ASP.NET&lt;br&gt;MicrosoftOfficeWebServer: 5.0_Pub&lt;br&gt;X-AspNet-Version: 2.0.50727&lt;br&gt;&lt;strong&gt;Set-Cookie: AppSessionCookie=vtd2qg55mkcypqnn53obxm45; path=/; HttpOnly&lt;/strong&gt;&lt;br&gt;Cache-Control: private&lt;br&gt;Content-Type: text/html; charset=utf-8&lt;br&gt;Content-Length: 1427&lt;/font&gt;&lt;/p&gt; &lt;p&gt;Notice that Session ID gets created at this stage by the server and is sent along with the response to the client. From now onwards Server will keep track of a user's session using this cookie. Note the session ID gets created at this stage&amp;nbsp;and not the authentication cookie. Remember Session key gets created the moment a successful transaction&amp;nbsp;occurs like a 200 OK between the server and the client.  &lt;p&gt;Step 5: Now the client has recieved the login.aspx page. It enters the credentials for username and password and sends it across to the server again. Notice that this is a POST request&amp;nbsp;to the login.aspx page now&amp;nbsp;and this time&amp;nbsp;it also sends credentials like username and password. We are sending the username and password as part of the Body of the request and not as part of the header.  &lt;p&gt;&lt;u&gt;&lt;em&gt;From Client&lt;/em&gt;&lt;/u&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;POST /FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx HTTP/1.1&lt;/strong&gt;&lt;br&gt;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*&lt;br&gt;&lt;strong&gt;Referer:&lt;/strong&gt; &lt;/font&gt;&lt;a href="http://saurabsi-sec/FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx" mce_href="http://saurabsi-sec/FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx"&gt;&lt;font color="#ff0000"&gt;http://saurabsi-sec/FormsAuthentication/login.aspx?&lt;strong&gt;ReturnUrl=%2fFormsAuthentication%2fdefault.aspx&lt;/strong&gt;&lt;/font&gt;&lt;/a&gt;&lt;br&gt;&lt;font color="#ff0000"&gt;Accept-Language: en-us&lt;br&gt;Content-Type: application/x-www-form-urlencoded&lt;br&gt;UA-CPU: x86&lt;br&gt;Accept-Encoding: gzip, deflate&lt;br&gt;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 1.1.4322; InfoPath.2)&lt;br&gt;Proxy-Connection: Keep-Alive&lt;br&gt;Content-Length: 277&lt;br&gt;Host: saurabsi-sec&lt;br&gt;Pragma: no-cache&lt;br&gt;&lt;strong&gt;Cookie: AppSessionCookie=vtd2qg55mkcypqnn53obxm45&lt;/strong&gt; &lt;/font&gt; &lt;p&gt;You have the option of sending it as a querystring too, in such a case it will form a part of the request header and not body.  &lt;p&gt;If you check the Queystring here, it shows ReturnUrl=/FormsAuthentication/default.aspx  &lt;p&gt;Also checking the forms body, we find:  &lt;p&gt;txtUser=john&lt;br&gt;txtPassword=test1&lt;br&gt;cmdLogin=Login  &lt;p&gt;Step 6: Server receives the credentials and then goes ahead and authenticates the user. Once the user has been authenticated server responds back with a 302 Found response ,asking the client to send another request for the originally requested page, i.e. Default.aspx. How it determines the original requested page as default.aspx? You are right, it's through the querystring that we just discussed above.  &lt;p&gt;&lt;u&gt;&lt;em&gt;From Server&lt;/em&gt;&lt;/u&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;HTTP/1.1 302 Found&lt;/strong&gt;&lt;br&gt;Date: Thu, 19 Apr 2007 07:11:50 GMT&lt;br&gt;Server: Microsoft-IIS/6.0&lt;br&gt;X-Powered-By: ASP.NET&lt;br&gt;MicrosoftOfficeWebServer: 5.0_Pub&lt;br&gt;X-AspNet-Version: 2.0.50727&lt;br&gt;&lt;/font&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;Location: /FormsAuthentication/default.aspx&lt;br&gt;Set-Cookie:&lt;/strong&gt; &lt;strong&gt;FormsAuthCookie=82A747623272A0A3A0C36EC6AD1FBA35A47592B1CFB38E54A1A7C5BC24ECAA2563715D4225EAE8927B98EC3DAD6FB9875E67FCA344AECCA19837A40B2311E373;&lt;/strong&gt; &lt;strong&gt;path=/; HttpOnly&lt;/strong&gt;&lt;br&gt;Cache-Control: private&lt;br&gt;Content-Type: text/html; charset=utf-8&lt;br&gt;Content-Length: 1590&lt;/font&gt;  &lt;p&gt;Notice the FormsAuthCookie here, this has been set by the server once it authenticates the user. Server goes ahead and sends back this authentication cookie along with the response back to the client. Now next time the client sends back any request in the same session it should have the authentication cookie as well apart from the Session Cookie that was set earlier. Server will recognize the user and the ongoing session with the client based on the cookies sent to it in future requests.  &lt;p&gt;Step 7: Now is the final round wherein Client after&amp;nbsp;done with all the validation process etc, goes ahead and sends&amp;nbsp;request for the Default.aspx page (remember it was also the very first&amp;nbsp;request sent by the client in the whole process).  &lt;p&gt;&lt;u&gt;&lt;em&gt;From client&lt;/em&gt;&lt;/u&gt;  &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;GET /FormsAuthentication/default.aspx HTTP/1.1&lt;/strong&gt;&lt;br&gt;Accept: image/gif, image/x-xbitmap, image/jpeg, image/pjpeg, application/x-ms-application, application/vnd.ms-xpsdocument, application/xaml+xml, application/x-ms-xbap, application/vnd.ms-excel, application/vnd.ms-powerpoint, application/msword, application/x-shockwave-flash, */*&lt;br&gt;&lt;strong&gt;Referer: &lt;/strong&gt;&lt;/font&gt;&lt;a href="http://saurabsi-sec/FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx" mce_href="http://saurabsi-sec/FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx"&gt;&lt;font color="#ff0000"&gt;http://saurabsi-sec/FormsAuthentication/login.aspx?ReturnUrl=%2fFormsAuthentication%2fdefault.aspx&lt;/font&gt;&lt;/a&gt;&lt;br&gt;&lt;font color="#ff0000"&gt;Accept-Language: en-us&lt;br&gt;UA-CPU: x86&lt;br&gt;Accept-Encoding: gzip, deflate&lt;br&gt;User-Agent: Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0; SLCC1; .NET CLR 2.0.50727; Media Center PC 5.0; .NET CLR 3.0.04506; .NET CLR 1.1.4322; InfoPath.2)&lt;br&gt;Proxy-Connection: Keep-Alive&lt;br&gt;Host: saurabsi-sec&lt;br&gt;Pragma: no-cache&lt;br&gt;&lt;strong&gt;Cookie: AppSessionCookie=vtd2qg55mkcypqnn53obxm45; FormsAuthCookie=82A747623272A0A3A0C36EC6AD1FBA35A47592B1CFB38E54A1A7C5BC24ECAA2563715D4225EAE8927B98EC3DAD6FB9875E67FCA344AECCA19837A40B2311E373&lt;/strong&gt;&lt;/font&gt;  &lt;p&gt;Notice the cookies here. You will see there are two cookies being sent to the server separated by ";".&amp;nbsp;One for the server to recognize the ongoing session with the client and the other one to recongize the authenticated user.  &lt;p&gt;Step 8: Server has nothing else to do&amp;nbsp;much but send back the response to the client for the requested web page.  &lt;p&gt;&lt;em&gt;&lt;u&gt;From Server&lt;/u&gt;&lt;/em&gt;&lt;/p&gt; &lt;p&gt;&lt;font color="#ff0000"&gt;&lt;strong&gt;HTTP/1.1 200 OK&lt;/strong&gt;&lt;br&gt;Date: Thu, 19 Apr 2007 07:11:50 GMT&lt;br&gt;Server: Microsoft-IIS/6.0&lt;br&gt;X-Powered-By: ASP.NET&lt;br&gt;MicrosoftOfficeWebServer: 5.0_Pub&lt;br&gt;X-AspNet-Version: 2.0.50727&lt;br&gt;Cache-Control: private&lt;br&gt;Content-Type: text/html; charset=utf-8&lt;br&gt;Content-Length: 1111&lt;/font&gt;&lt;/p&gt; &lt;p&gt;You might notice something here, in the web.config file we had set the timeout value for Forms authentication cookie to be 1 minute, and session cookie to be 2 minutes. So, you might see a scenario wherein let's say a user gets logged out because of expired authentication cookie. In our example let's say a user gets logged out after 1 minute (authentication cookie timeout value being set to 1 minute), and he is redirected to login page. He logs in back this time after entering the credentials in the login page. But this time he uses a different credentials to login.  &lt;p&gt;So what should happen, should the new user (with a different credentials this time) have access to all the original session variables (assuming session timeout has still not expired for the earlier user session) of the previous user&amp;nbsp;when the same browser instance is running?  &lt;p&gt;Answer is Yes, the new user with a different credentials this time will have access to all the session variables for the previous user, provided the same browser session is being used this time. Resaon being that the authentication cookie has expired but not the session cookie, so browser sends the vaild session cookies to the server and hence is able to access the session variables.  &lt;p&gt;If we use a different browser session, of course a new session cookie has to be obtained which will invalidate session variables for the prevoius user.  &lt;p&gt;Here&amp;nbsp;I haven't gone into troubleshooting session loss issues, rather i have focused on how forms authentication process occurs between client and the server. In case your eyes are looking for some good logical reading on troubleshooting Session loss issues in ASP.Net, a must READ&amp;nbsp;here &lt;a title="http://aspalliance.com/1182_Troubleshooting_Session_Related_Issues_in_ASPNET" href="http://aspalliance.com/1182_Troubleshooting_Session_Related_Issues_in_ASPNET" mce_href="http://aspalliance.com/1182_Troubleshooting_Session_Related_Issues_in_ASPNET"&gt;http://aspalliance.com/1182_Troubleshooting_Session_Related_Issues_in_ASPNET&lt;/a&gt;&lt;/p&gt;&lt;img src="http://blogs.msdn.com/aggbug.aspx?PostID=2190044" width="1" height="1"&gt;</description><category domain="http://blogs.msdn.com/saurabh_singh/archive/tags/ASP.Net/default.aspx">ASP.Net</category><category domain="http://blogs.msdn.com/saurabh_singh/archive/tags/Forms+Authentication/default.aspx">Forms Authentication</category></item></channel></rss>