title: How to check if user is logged in or not in forms based authentication
body: <p>I want to implement forms based authentication manually in my website.</p>
  
  <p>I am using <code>Web.config</code> file for data store</p>
  
  <pre><code>&lt;authentication mode="Forms"&gt;
    &lt;forms loginUrl="~/Login.aspx" 
           name=".ASPXAUTH"
           path="/"
           requireSSL="false"
           slidingExpiration="true"
           defaultUrl="~/Admin/OrderHistory.aspx"
           cookieless="UseDeviceProfile"
           enableCrossAppRedirects="false"
           &gt;
      &lt;credentials passwordFormat="Clear"&gt;
        &lt;user name="Admin" password="adm123$"/&gt;
        &lt;user name="Administrator" password="adm234%"/&gt;
      &lt;/credentials&gt;
    &lt;/forms&gt;
  &lt;/authentication&gt;
  &lt;authorization&gt;
    &lt;deny users ="?" /&gt;
    &lt;allow users = "*" /&gt;
  &lt;/authorization&gt;
  </code></pre>
  
  <p>There is a <code>Login.aspx</code> page at root level in that im using ASP.NET login control to get username and password.</p>
  
  <p>Everything works fine but when the user is <code>logged in</code> and manually go to <code>login.aspx</code> page, its not redirect the user to defaultUrl page.</p>
  
  <p>I want to redirect the user to a specific page/defaultUrl page, if he is logged in and came manually to login.aspx page</p>
  
  <p>How to do it?</p>
  
  <h2>Login Button-Click</h2>
  
  <pre><code>if (FormsAuthentication.Authenticate(LoginUser.UserName, LoginUser.Password))
      {
          FormsAuthentication.RedirectFromLoginPage(LoginUser.UserName, true);
  
      }
  </code></pre>