<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Coding</title>
        <link>http://blog-howto.com/category/27.aspx</link>
        <description>Software development topics</description>
        <language>en-US</language>
        <copyright>Dave's Tech Shop</copyright>
        <managingEditor>blogauthor@davestechshop.net</managingEditor>
        <generator>Subtext Version 1.9.0.27</generator>
        <item>
            <title>Building Subtext from the Source Code in Visual Studio</title>
            <link>http://blog-howto.com/archive/2006/09/24/SubtextInVisualStudio2005.aspx</link>
            <description>&lt;p&gt;I assume you have &lt;a target="_blank" rel="nofollow" href="http://msdn.microsoft.com/vstudio/"&gt;Visual Studio 2005&lt;/a&gt; and MS SQL Server installed already. &lt;/p&gt;
&lt;p&gt;The next step is to install Visual Studio 2005 &lt;strong&gt;Web Application Projects&lt;/strong&gt; (WAP). In case you need it, &lt;a target="_blank" rel="nofollow" href="http://forums.asp.net/1019/ShowForum.aspx"&gt;here&lt;/a&gt; is a link to the support forum for WAP.&lt;/p&gt;
&lt;p&gt;For some background on what WAP is, &lt;a target="_blank" href="http://webproject.scottgu.com/"&gt;ScottGu&lt;/a&gt; describes it as, &lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;em&gt;a new web project option for Visual Studio 2005 that provides the same conceptual web project approach as VS 2003 (a project file based structure where all code in the project is compiled into a single assembly) but with all the new features of VS 2005 (refactoring, class diagrams, test development, generics, etc) and ASP.NET 2.0 (master pages, data controls, membership/login, role management, Web Parts, personalization, site navigation, themes, etc)&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;ScottGu has some tutorials &lt;a target="_blank" href="http://webproject.scottgu.com/CSharp/Default.aspx"&gt;here&lt;/a&gt;. You &lt;strong&gt;won't&lt;/strong&gt; need to read them just to build Subtext, but they are great for understanding WAP in general. (Thanks Scott!)&lt;/p&gt;
&lt;p&gt;If you will be converting any VS 2003 projects to VS 2005, then you will want to start with this &lt;strong&gt;optional&lt;/strong&gt; step:&lt;/p&gt;
&lt;p&gt;Optionally install &lt;a target="_blank" href="http://207.46.19.60/downloads/details.aspx?familyid=7CECD652-FC04-4EF8-A28A-25C5006677D8"&gt;Microsoft Visual Studio 2005 - Update to the Web Project Conversion Wizard.&lt;/a&gt;&lt;/p&gt;
&lt;p&gt;It is my understanding that the prior Conversion Wizard doesn't work correctly with WAP. However, Subtext 1.9 and later are built for Visual Studio 2005 with WAP, so this step is &lt;strong&gt;not&lt;/strong&gt; required for Subtext. It is only required if you wish to work on other VS 2003 projects that you will be converting to VS 2005, which I assume most developers will want to do. Since it is recommended that this new Conversion Wizard be installed before WAP, I thought it best to point it out now.&lt;/p&gt;
&lt;p&gt;Now install &lt;a target="_blank" rel="nofollow" href="http://www.microsoft.com/downloads/details.aspx?FamilyId=8B05EE00-9554-4733-8725-3CA89DD9BFCA"&gt;Microsoft Visual Studio 2005 - Update to Support Web Application Projects&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You are finally ready to install WAP. Get it here: &lt;a target="_blank" rel="nofollow" href="http://msdn.microsoft.com/asp.net/reference/infrastructure/wap/default.aspx"&gt;Visual Studio 2005 Web Application Projects&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Next, install &lt;a target="_blank" href="http://tortoisesvn.tigris.org/"&gt;TortoiseSVN&lt;/a&gt; or your favorite Subversion (svn) client. To get Subtext 1.9 release, for example, point your svn client to &lt;a target="_blank" href="https://svn.sourceforge.net/svnroot/subtext/branches/Release1.9"&gt;https://svn.sourceforge.net/svnroot/subtext/branches/Release1.9&lt;/a&gt;. For more on Subversion access, see this SourceForge project &lt;a target="_blank" href="http://sourceforge.net/svn/?group_id=137896"&gt;page&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;Assuming you are using &lt;a target="_blank" href="http://tortoisesvn.tigris.org/"&gt;TortoiseSVN&lt;/a&gt; to get Subtext, follow these steps: &lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" alt="" align="right" border="0" src="http://www.blog-howto.com/images/articles/TortoiseSvnCheckout.jpg" /&gt; &lt;/p&gt;
&lt;p&gt;Make a new folder on your local hard drive, then right click the folder in Windows Explorer to access the TortoiseSVN context menu as shown to the right. &lt;/p&gt;
&lt;p&gt;Then supply the appropriate svn URL. &lt;/p&gt;
&lt;p&gt;In my example URL shown below, the command will check out the entire 1.9 release to a local folder on your drive called "C:\Projects\Subtext".&lt;/p&gt;
&lt;p&gt;&lt;img style="BORDER-TOP-WIDTH: 0px; BORDER-LEFT-WIDTH: 0px; BORDER-BOTTOM-WIDTH: 0px; BORDER-RIGHT-WIDTH: 0px" alt="" border="0" src="http://www.blog-howto.com/images/articles/TortoiseSvnCheckout2.jpg" /&gt;&lt;/p&gt;
&lt;p&gt;Now you are ready to open Subtext in Visual Studio. The VS solution file would be found here, in my example: &lt;strong&gt;C:\Projects\Subtext\SubtextSolution\SubtextSolution.sln&lt;/strong&gt;. &lt;/p&gt;
&lt;p&gt;Hopefully, success will come as easy for you as it did for me. All I did was open the solution and hit Ctrl-Shft-B and I was greeted by this:&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;========== Build: 10 succeeded or up-to-date, 0 failed, 0 skipped ==========&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Before you can deploy Subtext, you need to edit the configuration files (at least web.config) and then follow the standard installation steps.&lt;/p&gt;
&lt;p&gt;I have a very detailed article about editing the config files and deploying Subtext to WebHost4Life &lt;a href="http://blog-howto.com/archive/2006/09/09/InstallSubtextAtWH4L.aspx"&gt;here&lt;/a&gt;.&lt;/p&gt;
&lt;p&gt;You should also check out the Subtext project &lt;a target="_blank" href="http://www.subtextproject.com/Home/Docs/Installation/tabid/111/Default.aspx"&gt;installation page&lt;/a&gt;.&lt;/p&gt;&lt;img src="http://blog-howto.com/aggbug/255.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave's Tech Shop</dc:creator>
            <guid>http://blog-howto.com/archive/2006/09/24/SubtextInVisualStudio2005.aspx</guid>
            <pubDate>Sun, 24 Sep 2006 12:47:09 GMT</pubDate>
            <comments>http://blog-howto.com/archive/2006/09/24/SubtextInVisualStudio2005.aspx#feedback</comments>
            <wfw:commentRss>http://blog-howto.com/comments/commentRss/255.aspx</wfw:commentRss>
            <trackback:ping>http://blog-howto.com/services/trackbacks/255.aspx</trackback:ping>
        </item>
        <item>
            <title>Forms Authentication Cookies and Subdomain Names</title>
            <link>http://blog-howto.com/archive/2006/09/21/FormsAuthCookiesAndSubdomainNames.aspx</link>
            <description>&lt;p&gt;Does your ASP.NET web site have subdomains and use forms authentication with persistent cookies? Do you host your site or blog on a shared hosting platform? If so, you can run into a problem authenticating users because of the way cookie domains work. Here are the details of the problem and steps you can take to solve or prevent the problem.&lt;/p&gt;
&lt;h3&gt;Security or Login Problems Can Occur&lt;/h3&gt;
&lt;p&gt;For this example, let's assume you have a blog running blogging software (such as &lt;a target="_blank" href="http://subtextproject.com/"&gt;Subtext&lt;/a&gt;) that supports multiple blogs. Let's also assume you host at WebHost4Life because that is the assumption most articles on this blog have made so far. (However, this example also applies to all web sites with subdomains and forms authentication with cookies and shared hosting.) Say you have the following subdomains set up:&lt;/p&gt;
&lt;ul&gt;
    &lt;li&gt;&lt;strong&gt;http://example.com&lt;/strong&gt; (same as http://www.example.com - this is an aggregated blog or a home page) &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;http://racing.example.com&lt;/strong&gt; (this is your friend's blog about racing) &lt;/li&gt;
    &lt;li&gt;&lt;strong&gt;http://csharp.example.com&lt;/strong&gt; (this is your blog about C# software development) &lt;/li&gt;
    &lt;li&gt;and there could be any number of &lt;strong&gt;other subdomains&lt;/strong&gt; &lt;/li&gt;
&lt;/ul&gt;
&lt;p&gt;Assume you have user accounts at the aggregated blog (http://example.com) and the other blogs (e.g., http://csharp.example.com). When you log in to any of the blogs at this domain, ASP.NET writes an authentication cookie containing an authentication ticket for your login.&lt;/p&gt;
&lt;h3&gt;The Problem&lt;/h3&gt;
&lt;p&gt;&lt;strong&gt;Once you log in to &lt;/strong&gt;&lt;strong&gt;http://example.com&lt;/strong&gt;&lt;strong&gt;, you may find that you cannot log in to any of the subdomains&lt;/strong&gt;. This happens because the authentication cookies for specific subdomains have a limited cookie scope. &lt;em&gt;However&lt;/em&gt;, the authentication cookie for http://example.com is available to the primary domain and all subdomains.&lt;/p&gt;
&lt;h3&gt;Why the Problem Occurs&lt;/h3&gt;
&lt;p&gt;Let's say you have logged in to http://example.com earlier. Now you are logging in to http://csharp.example.com. When you log in, ASP.NET creates a FormsAuthenticationTicket with your username and some other information (such as IssueDate, Expiration, Version, etc.). This FormsAuthenticationTicket is stored in a cookie (for the type of configuration we are discussing). WebHost4Life (and probably other shared hosting providers) sets the cookie domain to be the actual domain specified in the URL. This cookie then belongs to that specific subdomain (the one you are logging in to). There are various security mechanisms that enforce this rule. &lt;/p&gt;
&lt;p&gt;In this example, the cookie will be named youruser@csharp.example[1].txt. (The number may not be 1. It is usually 1 or 2.) The cookie will be located at "C:\Documents and Settings\YourUser\Cookies". Your previous cookie (from logging in to the primary domain http://example.com)  will be named similar to youruser@example[1].txt and it will be in the same location.&lt;/p&gt;
&lt;p&gt;After you log in, you are transferred to another page (usually some resource that requires you to have logged in). The request for this page causes ASP.NET to execute code for AuthenticateRequest (or OnAuthenticateRequest in your custom code such as an HttpModule, for example). One thing that happens in that code is that the authentication cookie you created when you logged in is retrieved. The code to retrieve a cookie looks similar to this:&lt;/p&gt;
&lt;p&gt;        HttpContext.Current.Request.Cookies[cookieName]; &lt;/p&gt;
&lt;p&gt;where 'cookieName' is defined in web.config like this:&lt;/p&gt;
&lt;font size="2"&gt;&lt;font size="2"&gt;
&lt;p&gt; &lt;font color="#800000" size="2"&gt;&lt;font color="#0000ff"&gt;&amp;lt;&lt;/font&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;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;Forms&lt;/font&gt;&lt;font size="2"&gt;"&amp;gt;&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&lt;br /&gt;
  &amp;lt;&lt;/font&gt;&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;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;.MyCookieName&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;br /&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;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;login.aspx&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;br /&gt;
  &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;protection&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;All&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;br /&gt;
  &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;requireSSL&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;false&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; &lt;br /&gt;
  &lt;/font&gt;&lt;font color="#ff0000" size="2"&gt;slidingExpiration&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;=&lt;/font&gt;&lt;font size="2"&gt;"&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="#0000ff" size="2"&gt; &lt;br /&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;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;60&lt;/font&gt;&lt;font size="2"&gt;"&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt; /&amp;gt;&lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;&amp;lt;/&lt;/font&gt;&lt;font color="#800000" size="2"&gt;authentication&lt;font color="#0000ff"&gt;&amp;gt;&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;ASP.NET (or your custom module) will obtain the cookie value and decrypt the authentication ticket. It will then create an instance of an IPrincipal and assign that IPrincipal to HttpContext.Current.User. The IPrincipal will follow your entire request. That's how it should work anyway.&lt;/p&gt;
&lt;p&gt;However, in the situation, the cookie retrieved is the cookie from your previous login to the primary domain. This is the wrong cookie! At least it is wrong for our needs. (However, this behavior is by design. It is not a bug. Any cookie without a subdomain name is available to all subdomains and the primary domain.) This incorrect cookie contains an authentication ticket for the user account at the primary domain. Depending on how your code is written, the IPrincipal user account may not have the correct roles now. It probably doesn't have the correct user name. Obtaining the incorrect authentication ticket can have various serious problems, as you can imagine.&lt;/p&gt;
&lt;h3&gt;The Solution&lt;/h3&gt;
&lt;p&gt;ASP.NET retrieves cookies (within a domain) by name (e.g., ".MyCookieName" as configured above). Configurations like I am describing use the same cookie name for the primary domain and all subdomains. Changing that is one route to a solution -- assuming you do not have control over the cookie domain property, as is currently the case at WebHost4Life.&lt;/p&gt;
&lt;p&gt;If the cookie for http://csharp.example.com had a name similar to .MyCookieName.CSharp, then the normal ASP.NET code that retrieves the authentication cookie would work correctly. However, each subdomain needs a uniquely named cookie &lt;strong&gt;and there is no way to achieve this using the settings in web.config&lt;/strong&gt;.&lt;/p&gt;
&lt;p&gt;Therefore, you have to implement code to give each authentication cookie a unique name. Here is the approach I took recently. This is from code for the Subtext personal blog publishing platform. I decided to rely on the cookie name configured for forms authentication as the root name and attach various suffixes to this name to distinguish cookies for each subdomain.&lt;/p&gt;
&lt;p&gt;The 3 basic steps I took are:&lt;/p&gt;
&lt;ol&gt;
    &lt;li&gt;Create the unique cookie name; &lt;/li&gt;
    &lt;li&gt;Add the cookie to the response with the correct cookie name; &lt;/li&gt;
    &lt;li&gt;Select the correct cookie by name in AuthenticateRequest. &lt;/li&gt;
&lt;/ol&gt;
&lt;p&gt;First, I created a method that would create the suffix and then make a unique cookie name. In the case of Subtext, each subdomain is associated with a specific blog. Therefore, I named the cookies using blog identifiers. In the code below, I get the cookie name configured in web.config, and then I get the blog ID and make a unique cookie name.&lt;/p&gt;
&lt;font size="2"&gt;
&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;private&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;static&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string&lt;/font&gt;&lt;font size="2"&gt; GetFullCookieName(&lt;/font&gt;&lt;font size="2"&gt;)&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; cookieName = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.FormsCookieName;&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#008080" size="2"&gt;StringBuilder&lt;/font&gt;&lt;font size="2"&gt; name = &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;StringBuilder&lt;/font&gt;&lt;font size="2"&gt;(cookieName);&lt;br /&gt;
    name.Append(&lt;/font&gt;&lt;font color="#800000" size="2"&gt;"."&lt;/font&gt;&lt;font size="2"&gt;);&lt;br /&gt;
    &lt;/font&gt;&lt;font size="2"&gt;name.Append(&lt;/font&gt;&lt;font color="#008080" size="2"&gt;Config&lt;/font&gt;&lt;font size="2"&gt;.CurrentBlog == &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt; ? &lt;/font&gt;&lt;font color="#800000" size="2"&gt;"null"&lt;/font&gt;&lt;font size="2"&gt; : &lt;/font&gt;&lt;font color="#008080" size="2"&gt;Config&lt;/font&gt;&lt;font size="2"&gt;.CurrentBlog.Id.ToString());&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;return&lt;/font&gt;&lt;font size="2"&gt; name.ToString(); &lt;br /&gt;
}&lt;/font&gt; &lt;/p&gt;
&lt;p&gt;When setting the authentication ticket, I simply call the method above to get the correct (unique) cookie name. I included the entire method because the code shows something else of interest. As &lt;a target="_blank" href="http://www.hanselman.com/blog/AccessingTheASPNETFormsAuthenticationTimeoutValue.aspx"&gt;others&lt;/a&gt; have discovered, there is no good way to directly obtain the timeout value configured in web.config for cookie timeouts. The way I did it is by having ASP.NET make a temporary authentication cookie for me and then copying the timeout data (and other information too) from that temporary cookie. Once that is done, I simply set the correct cookie name and add the cookie to the response.&lt;/p&gt;
&lt;p&gt;NOTE: In ASP.NET 2.0, you may think you can use the strongly typed configuration classes to access values such as the authentication cookie timeout. However, that will not work in partial trust. You are making sure your web app will run in partial trust, right? If you don't want to take my approach for accessing the cookie timeout value, you could duplicate the web.config setting for forms authentication timeout in the appSettings section of your web.config file. Having the same value configured in two places is not ideal, however. That's why I chose the method shown below.&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;static&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; SetAuthenticationTicket(&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="#0000ff" size="2"&gt;bool&lt;/font&gt;&lt;font size="2"&gt; persist, &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;params&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;string &lt;/font&gt;&lt;font size="2"&gt;userData)&lt;br /&gt;
{&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#008000" size="2"&gt;//Getting a cookie this way and using a temp auth ticket &lt;br /&gt;
    &lt;/font&gt;&lt;font color="#008000" size="2"&gt;//allows us to access the timeout value from web.config in partial trust.&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpCookie&lt;/font&gt;&lt;font size="2"&gt; authCookie = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.GetAuthCookie(username, persist);&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthenticationTicket&lt;/font&gt;&lt;font size="2"&gt; tempTicket = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.Decrypt(authCookie.Value);&lt;br /&gt;
    &lt;/font&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;(&lt;br /&gt;
        &lt;/font&gt;&lt;font size="2"&gt;tempTicket.Version, tempTicket.Name, tempTicket.IssueDate,&lt;br /&gt;
        tempTicket.Expiration,&lt;/font&gt;&lt;font color="#008000" size="2"&gt;//this is how we access the configured timeout value&lt;br /&gt;
        &lt;/font&gt;&lt;font size="2"&gt;persist, &lt;/font&gt;&lt;font size="2"&gt;userData, &lt;/font&gt;&lt;font size="2"&gt;tempTicket.CookiePath);&lt;br /&gt;
    authCookie.Value = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;FormsAuthentication&lt;/font&gt;&lt;font size="2"&gt;.Encrypt(authTicket);&lt;br /&gt;
    authCookie.Name = GetFullCookieName();&lt;/font&gt;&lt;font color="#008000" size="2"&gt;//use our custom cookie name&lt;br /&gt;
    &lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpContext&lt;/font&gt;&lt;font size="2"&gt;.Current.Response.Cookies.Add(authCookie);&lt;br /&gt;
}&lt;/font&gt;&lt;/font&gt;&lt;/p&gt;
&lt;font size="2"&gt;
&lt;p&gt;ASP.NET can exhibit some bizarre behavior when it comes to cookies. Cookies can disappear during debugging and cookies can even be created out of thin air. In fact, the innocent act of getting a cookie from the Response cookie collection can create a cookie in the Request cookie collection! &lt;a target="_blank" href="http://www.codeproject.com/aspnet/aspnetcookies.asp?df=100&amp;amp;forumid=13312&amp;amp;exp=0&amp;amp;fr=26"&gt;Here&lt;/a&gt; is an excellent article by Paul Riley that covers all the details of those gotchas. Now, back to the specific solution.&lt;/p&gt;
&lt;p&gt;In your code that handles AuthenticateRequest, you need a way to select the correct authentication cookie by name. I used a method called SelectAuthenticationCookie. The code below shows the call site.&lt;/p&gt;
&lt;p&gt;&lt;font size="2"&gt;&lt;/font&gt;&lt;font size="2"&gt;&lt;font size="2"&gt;&lt;font color="#0000ff" size="2"&gt;void&lt;/font&gt;&lt;font size="2"&gt; OnAuthenticateRequest(&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="#008080" size="2"&gt;HttpCookie&lt;/font&gt;&lt;font size="2"&gt; authCookie = Subtext.Framework.&lt;/font&gt;&lt;font color="#008080" size="2"&gt;Security&lt;/font&gt;&lt;font size="2"&gt;.SelectAuthenticationCookie();&lt;br /&gt;
    //the rest of your authetication code would follow this.&lt;br /&gt;
}&lt;/font&gt;&lt;/font&gt;&lt;/font&gt; &lt;/p&gt;
&lt;p&gt;The method is implemented as shown below. Note that it uses the same GetFullCookieName method created above. In the code below, I use a for-loop, but I assume you may want to use some other type of loop (foreach?). I am trusting the jitter to handle the multiple calls to GetFullCookieName efficiently.&lt;/p&gt;
&lt;p&gt;&lt;font color="#0000ff" size="2"&gt;public&lt;/font&gt;&lt;font size="2"&gt; &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;static&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; SelectAuthenticationCookie()&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; authCookie = &lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;null&lt;/font&gt;&lt;font size="2"&gt;;&lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;    for&lt;/font&gt;&lt;font size="2"&gt; (&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;int&lt;/font&gt;&lt;font size="2"&gt; i = 0; i &amp;lt; &lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpContext&lt;/font&gt;&lt;font size="2"&gt;.Current.Request.Cookies.Count; ++i)&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; c = &lt;/font&gt;&lt;font color="#008080" size="2"&gt;HttpContext&lt;/font&gt;&lt;font size="2"&gt;.Current.Request.Cookies[i];&lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;        if&lt;/font&gt;&lt;font size="2"&gt; (c.Name == GetFullCookieName())&lt;br /&gt;
        {&lt;br /&gt;
            authCookie = c;&lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;           break&lt;/font&gt;&lt;font size="2"&gt;;&lt;br /&gt;
        }&lt;br /&gt;
    }&lt;br /&gt;
&lt;/font&gt;&lt;font color="#0000ff" size="2"&gt;    return&lt;/font&gt;&lt;font size="2"&gt; authCookie;&lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;As you can see, the code sets and gets the cookie by using the same GetFullCookieName method. That's all it takes to solve this problem.&lt;/p&gt;
&lt;p&gt;If you want to look at a running example of the code, go to the &lt;a target="_blank" href="http://sourceforge.net/projects/subtext"&gt;Subtext project&lt;/a&gt; and use &lt;a target="_blank" href="http://subversion.tigris.org/"&gt;Subversion&lt;/a&gt; to get rev 1762 or later of release 1.9, which is currently located at &lt;a href="https://svn.sourceforge.net/svnroot/subtext/branches/Release1.9/"&gt;https://svn.sourceforge.net/svnroot/subtext/branches/Release1.9/&lt;/a&gt;. (FYI, I assume this code will change completely in Subtext 2.0 when it is released. It could change before that.)&lt;/p&gt;
&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;/font&gt;&lt;img src="http://blog-howto.com/aggbug/249.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Dave's Tech Shop</dc:creator>
            <guid>http://blog-howto.com/archive/2006/09/21/FormsAuthCookiesAndSubdomainNames.aspx</guid>
            <pubDate>Thu, 21 Sep 2006 22:40:51 GMT</pubDate>
            <comments>http://blog-howto.com/archive/2006/09/21/FormsAuthCookiesAndSubdomainNames.aspx#feedback</comments>
            <wfw:commentRss>http://blog-howto.com/comments/commentRss/249.aspx</wfw:commentRss>
            <trackback:ping>http://blog-howto.com/services/trackbacks/249.aspx</trackback:ping>
        </item>
    </channel>
</rss>