MVC Login. User.Identity always empty
<p>I am trying to save information about the login in the HttpContext.Current.User.Identity in a asp.net-mvc5 proyect. But allways is empty.</p>

<p>Firt of all, a have a View with controller.
When you click on login button, call to the controller:</p>

<pre><code>public ActionResult Button1_Click(string user, string pass)
{
    bool result = _model.ValidateLogin(user, pass, 3, false);

    DirectResult r = new DirectResult();

    // Do some Authentication...
    if (!result)
    {
        r.Success = false;
        r.ErrorMessage = "Invalid username or password.";
    }

    return r;
}
</code></pre>

<p>The method ValidateLogin, first check the user is on database, and with the id create a cookie:</p>

<pre><code>DateTime now = DateTime.Now;
System.Web.Security.FormsAuthentication.Initialize();
System.Web.Security.FormsAuthenticationTicket ticket = new System.Web.Security.FormsAuthenticationTicket(1, userId.ToString(), now, now.Add(System.Web.Security.FormsAuthentication.Timeout), checkRemember, string.Empty, System.Web.Security.FormsAuthentication.FormsCookiePath);
string hash = System.Web.Security.FormsAuthentication.Encrypt(ticket);
System.Web.HttpCookie cookie = new System.Web.HttpCookie(System.Web.Security.FormsAuthentication.FormsCookieName, hash);
if (ticket.IsPersistent)
 cookie.Expires = now.AddYears(1);
System.Web.HttpContext.Current.Response.Cookies.Add(cookie);
</code></pre>

<p>But when i try to check the User.Identify always is empty and "IsAuthenticated" is false:</p>

<pre><code>protected override System.Security.Principal.IIdentity GetClientIdentity()
{
    IIdentity identity = System.Web.HttpContext.Current.User.Identity;
    if (identity.IsAuthenticated)
        return identity;
    else
        throw new AuthorizationDeniedException("Not logged in",false);

}
</code></pre>

<p>Why? Any idea?</p>

<p><strong>Edit for add web.config:</strong></p>

<p>In the web config, i have:</p>

<pre><code> &lt;authentication mode="Forms"&gt;
      &lt;forms loginUrl="~/Login/Index" protection="All" timeout="120" name=".ASPXAUTH" path="/" requireSSL="false" slidingExpiration="true" defaultUrl="default.html" cookieless="UseDeviceProfile" enableCrossAppRedirects="false"/&gt;
 &lt;/authentication&gt;
 &lt;authorization&gt;
      &lt;deny users="?"/&gt;
 &lt;/authorization&gt;
 &lt;location path="Login"&gt;
      &lt;system.web&gt;
           &lt;authorization&gt;
                &lt;allow users="*"/&gt;
           &lt;/authorization&gt;
      &lt;/system.web&gt;
 &lt;/location&gt;
</code></pre>