title: How to override/change FormsAuthentication LoginUrl in certain cases
body: <p>Is there a way to dynamically change the LoginUrl of FormsAuthentication?  What I have is the whole site protected by FormsAuth, but for some pages in a sub folder, I'd like to take the user to different login page, and have FormsAuth handle the ReturnUrl stuff.  Is that possible or do I have to write my own redirect code for the sub folder cases?</p>
  
  <p>Here's an example layout:</p>
  
  <pre><code>   ~/LogOn1.aspx
     ~/Protected1.aspx
     ~/Protected2.aspx
     ~/Subfolder/
     ~/Subfolder/LogOn2.aspx
     ~/Subfolder/NotProtected.aspx
     ~/Subfolder/Protected3.aspx
  </code></pre>
  
  <p>So my web.config looks like:</p>
  
  <pre><code> &lt;forms loginUrl="~/Splash.aspx" ... /&gt;
  </code></pre>
  
  <p>All of the Protected*.aspx pages have </p>
  
  <pre><code> &lt;deny users="?"&gt;
  </code></pre>
  
  <p>What I'd like though, is for ~/Subfolder/Protected3.aspx to be redirected to ~/Subfolder/LogOn2.aspx if the user is anonymous.</p>
  
  <p>I did try putting a stripped down version of web.config at ~/Subfolder/web.config:</p>
  
  <pre><code>&lt;?xml version="1.0"?&gt;
  &lt;configuration&gt;
     &lt;system.web&gt;
        &lt;authentication mode="Forms"&gt;
           &lt;forms loginUrl="~/Subfolder/LogOn.aspx" name="SiteAuth" protection="All" timeout="30" path="/" defaultUrl="~/Subfolder/default.aspx" requireSSL="true" cookieless="UseCookies" enableCrossAppRedirects="false" /&gt;
        &lt;/authentication&gt;
        &lt;authorization&gt;
           &lt;deny users="?" /&gt;
        &lt;/authorization&gt;
     &lt;/system.web&gt;
  &lt;/configuration&gt;
  </code></pre>
  
  <p>But all that gets me is this error:</p>
  
  <blockquote>
    <p>It is an error to use a section
    registered as
    allowDefinition='MachineToApplication'
    beyond application level.  This error
    can be caused by a virtual directory
    not being configured as an application
    in IIS.</p>
  </blockquote>
  
  <p>I think making the Subfolder dir an application would cause even more problems at this point, but maybe I am wrong.  If it was an application, wouldn't that separate all code in ~/Subfolder from the rest of the parent app?</p>