Authentication - Current.User.Identity returning null

Asked

Viewed 314 times

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 checking if 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 I always get the ID.Name as null.

  • In your User method.Firstordefault(). ID is returning something? Because I did it here in C#, pretty much the same and it worked. In my opinion I think that if you remove . Firstordefault() and put only User.ID will work.

  • Does your user really exist? Your Getusuario method is returning something?

1 answer

2


Tries:

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.