<?xml version="1.0" encoding="UTF-8" ?>
<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/"><channel><title>Common things to check when using Forms Authentication</title><link>https://community.telligent.com/community/11/w/user-documentation/67611/common-things-to-check-when-using-forms-authentication</link><description /><dc:language>en-US</dc:language><generator>14.0.0.586 14</generator><item><title>Common things to check when using Forms Authentication</title><link>https://community.telligent.com/community/11/w/user-documentation/67611/common-things-to-check-when-using-forms-authentication</link><pubDate>Wed, 09 Dec 2020 21:50:45 GMT</pubDate><guid isPermaLink="false">84691bd3-9b5e-4840-a1e4-1a7544492726</guid><dc:creator>Michael Kelley</dc:creator><comments>https://community.telligent.com/community/11/w/user-documentation/67611/common-things-to-check-when-using-forms-authentication#comments</comments><description>Current Revision posted to User Documentation by Michael Kelley on 12/09/2020 21:50:45&lt;br /&gt;
&lt;p&gt;[toc]&lt;/p&gt;
&lt;p&gt;When using the Forms Authentication module, there are a couple of areas to check first when troubleshooting any issues you might encounter when setting it up. These include the authentication ticket name, the machine keys, the cookie path, and the cookie domain.&lt;/p&gt;
&lt;h2 id="authentication_ticket_name"&gt;&lt;a name="Authentication_ticket_name"&gt;&lt;/a&gt;Authentication ticket name&lt;/h2&gt;
&lt;p&gt;&lt;i&gt;&lt;/i&gt;The most common issue when using Forms Authentication is that the name of the cookie used for the authentication ticket is different between the two applications. Forms Authentication works by creating a certain cookie that contains basic information about the user. The name of the cookie is set in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;. In ASP.NET, the default name is&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;ldquo;.ASPXAUTH&amp;rdquo;&lt;/span&gt;, however Telligent Community Server&amp;#39;s&amp;nbsp;out-of-the-box&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;sets it to&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;ldquo;.Zimbra.Evolution&amp;rdquo;&lt;/span&gt;. If the two applications do not have the same name set, then the other application will not recognize the authentication ticket from the main application.&lt;br /&gt;&lt;br /&gt;To change this, you can either change the main application to match Community Server&amp;#39;s&amp;nbsp;setting by changing its&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;lt;forms&amp;gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;line in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;to&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&amp;ldquo;.CommunityServer&lt;/span&gt;&amp;rdquo;, or you can change Community Server to use the same setting as your own application, but changing its&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;to use&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&amp;ldquo;.ASPXAUTH&amp;rdquo;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;or whatever it already has specified. An example is:&lt;/p&gt;
&lt;div class="code"&gt;
&lt;blockquote&gt;&lt;tt&gt;&amp;lt;authentication mode=&amp;quot;Forms&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/tt&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;lt;forms name=&amp;quot;.Zimbra.Evolution&amp;quot; ... /&amp;gt;&lt;/span&gt;&lt;tt&gt;&lt;br /&gt;&amp;lt;/authentication&amp;gt;&lt;br /&gt;&lt;/tt&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;h2 id="machine_keys"&gt;&lt;a name="Machine_keys"&gt;&lt;/a&gt;Machine keys&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;When using Forms Authentication between two ASP.NET applications, you need to ensure that the machine keys between the two applications match. The machine keys are used to encrypt and decrypt the information within the authentication ticket. If they do not match, one application will not be able to utilize the other application&amp;rsquo;s authentication ticket.&lt;br /&gt;&lt;br /&gt;The machine keys are set within the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;lt;system.web&amp;gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;section of the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;. A sample machine key section looks like this:&lt;/p&gt;
&lt;div class="code"&gt;
&lt;blockquote&gt;&lt;tt&gt;&amp;lt;machineKey&lt;br /&gt;&amp;nbsp; validationKey=&amp;quot;CFBAC2E26EB8...174C6901CE50D&amp;quot;&lt;br /&gt;&amp;nbsp; decryptionKey=&amp;quot;43AEA5079E&amp;hellip;97035372A&amp;quot;&lt;br /&gt;&amp;nbsp; validation=&amp;quot;SHA1&amp;quot; /&amp;gt;&lt;br /&gt;&lt;/tt&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;h2 id="cookie_paths"&gt;&lt;a name="Cookie_paths"&gt;&lt;/a&gt;Cookie paths&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;A frequent issue with the cookie created for the authentication ticket is the path on the cookie. Typically, an application will create the cookie with its path set to its own application path. So if your application is at&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;/app&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;and&amp;nbsp;Community Server is at&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;/tc&lt;/span&gt;, when you set the authentication cookie within&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;/app&lt;/span&gt;, ASP.NET will automatically set the cookie&amp;rsquo;s path to&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;/app&lt;/span&gt;. Then the browser will only pass the cookie along to page requests under&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;/app&lt;/span&gt;, and not to&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;/tc&lt;/span&gt;. To get it to carry over, you&amp;rsquo;ll need to set the cookie&amp;rsquo;s path to&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;/&lt;/span&gt;, so that it will be accessible between the two applications.&lt;br /&gt;&lt;br /&gt;The cookie&amp;rsquo;s path can either be specified in the&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;web.config&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;or through code. To set it in the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;, use the path attribute on the&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&amp;lt;forms&amp;gt;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;line in the parent application&amp;#39;s&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;, such as:&lt;/p&gt;
&lt;div class="code"&gt;
&lt;blockquote&gt;&lt;tt&gt;&amp;lt;authentication mode=&amp;quot;Forms&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/tt&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;lt;forms name=&amp;quot;.Zimbra.Evolution&amp;quot;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;... path=&amp;quot;/&amp;quot; /&amp;gt;&lt;/span&gt;&lt;tt&gt;&lt;br /&gt;&amp;lt;/authentication&amp;gt;&lt;br /&gt;&lt;/tt&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;p&gt;Additionally, it can be set in code when you use the&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;GetAuthCookie&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;method of&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;FormsAuthentication&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;instead of just the&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;SetAuthCookie&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;method when creating the cookie in the parent application. For example:&lt;/p&gt;
&lt;div class="code"&gt;
&lt;blockquote&gt;&lt;tt&gt;HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, true);&lt;br /&gt;cookie.Path = &amp;quot;/&amp;quot;;&lt;br /&gt;Response.Cookies.Add(cookie);&lt;br /&gt;&lt;/tt&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;h2 id="cookie_domains"&gt;&lt;a name="Cookie_domains"&gt;&lt;/a&gt;Cookie domains&lt;/h2&gt;
&lt;p&gt;&lt;b&gt;&lt;i&gt;&lt;/i&gt;&lt;/b&gt;Another common issue with the cookie for the authentication is the domain for the cookie. Similarly to the paths of the cookies, if the cookies are created on two different subdomains, then the cookie will only be accessible on the domain where it was created. For instance your main application may be on&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;www.domain.com&lt;/span&gt;, but you have&amp;nbsp;Community Server running on&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;tc&lt;/span&gt;.domain.com. If you create the cookie on&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;www.domain.com&lt;/span&gt;, the browser will only send it to that domain, and it won&amp;rsquo;t be passed along when they navigate over to&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;tc&lt;/span&gt;.domain.com.&lt;br /&gt;&lt;br /&gt;The cookie can be carried over by setting the domain to&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&amp;ldquo;.domain.com&amp;rdquo;&lt;/span&gt;.&amp;nbsp; Cookies don&amp;rsquo;t use the common&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;ldquo;*&amp;rdquo;&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;wild card. Simply use&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;ldquo;.domain.com&amp;rdquo;&lt;/span&gt;. With this entry, the browser will not &amp;nbsp;pass the cookie when it goes over to&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;cs.domain.com&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;as well.&lt;br /&gt;&lt;br /&gt;Like the path, the domain can be specified in either the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;or through code. When setting the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;web.config&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;/span&gt;file, it will only check for the authorization cookie. You must have this set for the site to correctly recognize the new domain level cookie:&lt;/p&gt;
&lt;div class="code"&gt;
&lt;blockquote&gt;&lt;tt&gt;&amp;lt;authentication mode=&amp;quot;Forms&amp;quot;&amp;gt;&lt;br /&gt;&amp;nbsp; &amp;lt;forms name=&amp;quot;.Zimbra.Evolution&lt;/tt&gt;&lt;tt&gt;&amp;quot; ... domain=&amp;quot;.domain.com&amp;quot; /&amp;gt;&lt;br /&gt;&amp;lt;/authentication&amp;gt;&lt;br /&gt;&lt;/tt&gt;&lt;/blockquote&gt;
&lt;/div&gt;
&lt;p&gt;The&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;&amp;quot;domain&amp;quot;&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;name is ignored by the&lt;span style="font-family:courier new,courier;"&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;FormsAuthentication.SetAuthCookie&lt;/span&gt;&lt;span&gt;&amp;nbsp;&lt;/span&gt;method, so you must manually set it on your login page when creating the&lt;span&gt;&amp;nbsp;&lt;/span&gt;&lt;span style="font-family:courier new,courier;"&gt;AuthCookie&lt;/span&gt;. For example:&lt;/p&gt;
&lt;div class="code"&gt;
&lt;blockquote&gt;&lt;tt&gt;HttpCookie cookie = FormsAuthentication.GetAuthCookie(username, true);&lt;br /&gt;&lt;/tt&gt;&lt;/blockquote&gt;
&lt;p&gt;&lt;tt&gt;cookie.Domain = &amp;quot;.domain.com&amp;quot;;&lt;br /&gt;Response.Cookies.Add(cookie);&lt;/tt&gt;&lt;/p&gt;
&lt;/div&gt;&lt;div style="clear:both;"&gt;&lt;/div&gt;
</description></item></channel></rss>