<p>I'm working on a internal web based tool for my company. Part of this tool is another application (The Cruise Control Dashboard) that runs in its own Virtual Directory under my root application.</p>

<p>I wanted to limit access to this internal application by setting up Forms Authentication on it, and having a login form in the root application.</p>

<p>I put the following into the root applications web.config:</p>

<pre><code>&lt;location path="ccnet"&gt;
  &lt;system.web&gt;
    &lt;authentication mode="Forms"&gt;
        &lt;forms loginUrl="/default.aspx" timeout="5000"/&gt;
    &lt;/authentication&gt;
    &lt;authorization&gt;
      &lt;allow users="?"/&gt;
      &lt;deny users="?"/&gt;
    &lt;/authorization&gt;        
  &lt;/system.web&gt;    
&lt;/location&gt;
</code></pre>

<p>However, the Forms Authentication does not appear to be working, it does not redirect back to the login page when I access that application directly.</p>

<p>I have a feeling I have the &lt;allow&gt; and &lt;deny&gt; tags set wrong. Can someone clarify?</p>

[{'answer_id': 19239, 'author': 'Darren Kopp', 'author_id': 77, 'author_profile': 'https://Stackoverflow.com/users/77', 'pm_score': 0, 'selected': False, 'text': '<p>you are allowing all unauthenticated. You might be looking for something like this</p>\n\n<pre><code>&lt;deny users="?"/&gt;\n</code></pre>\n'}, {'answer_id': 19253, 'author': 'Mark Glorie', 'author_id': 952, 'author_profile': 'https://Stackoverflow.com/users/952', 'pm_score': 0, 'selected': False, 'text': '<blockquote>\n  <p>That does not work, it still allows all users, (Authenticated or not) to access.  </p>\n</blockquote>\n\n<p>I would think you could even omit the allow tag, as it\'s redundant. Just:</p>\n\n<pre><code>&lt;deny users="?"/&gt;\n</code></pre>\n'}, {'answer_id': 19287, 'author': 'David Wengier', 'author_id': 489, 'author_profile': 'https://Stackoverflow.com/users/489', 'pm_score': 2, 'selected': False, 'text': '<p>FormsAuthentication encrypts the tokens that it gives to the user, and by default it encrypts keys different for each application. To get Forms Auth to work across applications, there are a couple of things you need to do:</p>\n\n<p>Firstly, set the Forms Auth "name" the same on all Applications. This is done with:</p>\n\n<pre><code>&lt;authentication mode="Forms"&gt;  \n    &lt;forms name="{name}" path="/" ...&gt;\n&lt;/authentication&gt;\n</code></pre>\n\n<p>Set the "name" to be the same in both applications web.configs.</p>\n\n<p>Secondly, you need to tell both applications to use the same key when encrypting. This is a bit confusing. When I was setting this up, all I had to do was add the following to both web.configs:</p>\n\n<pre><code>&lt;machineKey validationKey="AutoGenerate" decryptionKey="AutoGenerate" validation="SHA1" /&gt;\n</code></pre>\n\n<p>According to the docs, thats the default value, but it didnt work for me unless I specified it.</p>\n'}, {'answer_id': 19291, 'author': 'Mark Glorie', 'author_id': 952, 'author_profile': 'https://Stackoverflow.com/users/952', 'pm_score': 0, 'selected': False, 'text': "<p>Where does that code sit Jonathan? In my experience I have a login control and in the OnAuthenticate event I would set Authenticated to false...   </p>\n\n<pre><code>If CustomAuthenticate(Login1.UserName, Login1.Password) Then\n    FormsAuthentication.RedirectFromLoginPage(Login1.UserName, False)\nElse\n    e.Authenticated = False\nEnd If\n</code></pre>\n\n<p>But that's using the <em>Microsoft Way</em> </p>\n"}, {'answer_id': 19309, 'author': 'David Wengier', 'author_id': 489, 'author_profile': 'https://Stackoverflow.com/users/489', 'pm_score': 2, 'selected': True, 'text': '<p>You might also need to put path="/"  in the &lt;forms tag(s) I think. Sorry, its been a while since i\'ve done this</p>\n'}, {'answer_id': 19316, 'author': 'FlySwat', 'author_id': 1965, 'author_profile': 'https://Stackoverflow.com/users/1965', 'pm_score': 3, 'selected': False, 'text': '<blockquote>\n  <p>You might also need to put path="/" in the \n</blockquote>\n\n<p>That was it!</p>\n\n<p>So, Summary, inorder todo this;</p>\n\n<p>In root web.config add:</p>\n\n<pre><code>&lt;machineKey validationKey="AutoGenerate" decryptionKey="AutoGenerate" validation="SHA1" /&gt;\n</code></pre>\n\n<p>This must be done because by default it is "AutoGenerate,IsolateApps".</p>\n\n<p>Second, you must name the form Auth cookie the same in both, I did this all in my root, using the location tag:</p>\n\n<pre><code>&lt;authentication mode="Forms"&gt;\n   &lt;forms name="ccAuth" loginUrl="/default.aspx"  path="/" timeout="5000"/&gt;\n&lt;/authentication&gt;\n&lt;authorization&gt;\n   &lt;deny users="?"/&gt;\n&lt;/authorization&gt;\n</code></pre>\n\n<p>Finally:</p>\n\n<pre><code>&lt;location path="ccnet"&gt;\n  &lt;system.web&gt;\n    &lt;authentication mode="Forms"&gt;\n      &lt;forms name="ccAuth" loginUrl="/default.aspx"  path="/" timeout="5000"/&gt;\n    &lt;/authentication&gt;\n    &lt;authorization&gt;\n      &lt;deny users="?"/&gt;\n    &lt;/authorization&gt;      \n  &lt;/system.web&gt;    \n&lt;/location&gt;\n</code></pre>\n\n<p>Thanks everyone for your help. This was a stumper.</p>\n'}, {'answer_id': 326127, 'author': 'MatthewMartin', 'author_id': 33264, 'author_profile': 'https://Stackoverflow.com/users/33264', 'pm_score': 0, 'selected': False, 'text': '<p>What is the file extension for this cruise control application?  If it is not a file type that ASP.NET is registered to handle (e.g. jsp, java, etc), then ASP.NET will not act as an authentication mechanism (on IIS 5 and 6).  For example, for static html files, unless you have wildcard mapping implemented, IIS does all the authentication and authorization and serves up the file without involving the ASP.NET isapi extension.  IIS7 can use the new integrated pipeline mode to intercept all requests. For IIS6, you\'ll want to look at <a href="http://weblogs.asp.net/scottgu/archive/2007/03/04/tip-trick-integrating-asp-net-security-with-classic-asp-and-non-asp-net-urls.aspx" rel="nofollow noreferrer">Scott Gu\'s article on the matter</a>.</p>\n'}, {'answer_id': 41677870, 'author': 'Kevin Pluck', 'author_id': 1507920, 'author_profile': 'https://Stackoverflow.com/users/1507920', 'pm_score': 0, 'selected': False, 'text': '<p>None of the above suggestions worked for me.  Turns out in the root web.config set:</p>\n\n<pre><code>&lt;forms loginUrl="/pages/login.aspx" enableCrossAppRedirects="true"...\n</code></pre>\n\n<p>and make sure that both the root and child app have in system.web</p>\n\n<pre><code>&lt;machineKey validationKey="AutoGenerate" decryptionKey="AutoGenerate" validation="SHA1"/&gt;\n</code></pre>\n\n<p>which turns off the IsolateApps default.</p>\n\n<p>Then everything just worked!</p>\n'}]
['https://Stackoverflow.com/questions/19236', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1965/']