How can i have ASP.net automatically redirect non-logged in Forms users to the login page?
<p>i have an ASP.net website. </p>

<p>i want users who are not logged in to be automatically (re)directed to the login page, e.g.:</p>

<pre><code>~/Account/Login.aspx 
</code></pre>

<p>As it is now users are able to visit pages (e.g. <code>default.aspx</code>) without being logged in.</p>

<hr>

<p><strong>Note</strong>: i am operating on the (perhaps incorrect) assumption that ASP.net as its own authentication cycle that happens behind my back before every (and any) page loads.</p>

<hr>

<p><strong>Update</strong> @asawyer provided a link that, while not helping to answer the question, did provide a pretty graphic:</p>

<p><img src="http://i.stack.imgur.com/X2OIN.png" alt="enter image description here"></p>

<h2>Well what have you tried?</h2>

<p>i have a <code>web.config</code> file that enables <strong>Forms</strong> authentication:</p>

<pre><code>&lt;?xml version="1.0"?&gt;
...
&lt;configuration&gt;
   ...
   &lt;system.web&gt;
      &lt;authentication mode="Forms"&gt;
         &lt;forms loginUrl="~/Account/Login.aspx" name=".ASPXFORMSAUTH" slidingExpiration="true"/&gt;
      &lt;/authentication&gt;
      ...
   &lt;/system.web&gt;
   ...
&lt;/configuration&gt;
</code></pre>

<p>When i browser to the "default" page, i am able to view it, e.g.:</p>

<pre><code>GET http://localhost:53149/WebSite/ HTTP/1.1
Host: localhost:53149
</code></pre>

<p>and i'm get the page contents:</p>

<pre><code>HTTP/1.1 200 OK
Server: ASP.NET Development Server/10.0.0.0
</code></pre>

<p>In other words rather than being <em>forced</em> to login to the web-site, i am <strong><em>not</em></strong> being forced to login to the web-site.</p>

<p>It might be related to the fact that my browser is running locally to the web-server; but i'm using <code>Forms</code>, not <code>Windows</code> (and not <code>Passport</code> and not <code>None</code>) authentication.</p>

<h2>Bonus Reading</h2>

<ul>
<li><a href="http://www.asp.net/web-forms/tutorials/security/introduction/an-overview-of-forms-authentication-cs" rel="nofollow">An Overview of Forms Authentication (C#)</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/9wff0kyh.aspx" rel="nofollow">MSDN: Forms Authentication Provider</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/330a99hc.aspx" rel="nofollow">MSDN: ASP.NET Web Application Security</a></li>
<li><a href="https://wiki.jasig.org/display/CASC/ASP.NET+Forms+Authentication" rel="nofollow">ASP.NET Forms Authentication</a></li>
<li><a href="http://stackoverflow.com/questions/1574735/require-user-to-login-to-view-document-using-asp-net">Require user to login to view document using ASP.NET</a></li>
<li><a href="http://stackoverflow.com/questions/2900931/protect-some-pages-from-direct-access-asp-net">Protect some pages from direct access ASP.NET</a></li>
<li><a href="http://msdn.microsoft.com/en-us/library/k3fc21xw" rel="nofollow">FormsAuthentication Class</a></li>
</ul>
