Authentication - Current.User.Identity returning null

3

My login

 Dim senha = "null"
    If Not (senhaLogin.Text = "") Then
        senha = senhaLogin.Text
    End If
    Dim Usuario = GetUsuario.Where(Function(a) a.Email = emailLogin.Text And a.Senha = senha)
    If Usuario.Count > 0 Then
        Dim userName = Usuario.FirstOrDefault().ID
        FormsAuthentication.SetAuthCookie(userName, False)
        Response.Redirect("Default.aspx")
    End If

My validation that verifies that the user is authenticated

Dim ID = System.Web.HttpContext.Current.User.Identity
If ID.Name = "" Then
    Response.Redirect("login.aspx")
End If

My problem is that I always get ID.Name as null.

    
asked by anonymous 30.03.2015 / 21:03

1 answer

2

Try:

Dim senha = Nothing
If Not (senhaLogin.Text = "") Then senha = senhaLogin.Text
Dim Usuario = GetUsuario.Where(Function(a) a.Email = emailLogin.Text : a.Senha = senha)
If Usuario.Count > 0 Then
    Dim userName As String = Usuario.FirstOrDefault().ID.ToString()
    FormsAuthentication.SetAuthCookie(userName, False)
    Response.Redirect("Default.aspx")
End If
    
07.05.2015 / 20:52