1
  //GET api/Account/AllUsers
    [Route("AllUsers")]
    public List<IdentityUser> GetUsers()
    {
        var users = UserManager.Users.ToList();
        return users;
        //return query;
    }  

ERROR

This is the returned error, nothing else is occurring when this Route is called. The only time the ApplicationUser is called is during the login process, which I then navigate to this view and call this route on the page load which errors out. Not sure if it's EntityFramework, code on the backend or ignorance.

    public class ApplicationUser : IdentityUser
{
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public string BirthDate { get; set; }
    public bool IsDriver { get; set; }
    public DateTime CreatedDate { get; set; }
}

public class ApplicationDbContext : IdentityDbContext<ApplicationUser> 
{
    public ApplicationDbContext()
        : base("DmmContext", false)            
    {

    }

}

The above is the ApplicationUser class.

     //GET api/Account/AllUsers
    [Route("AllUsers")]
    public List<ApplicationUser> GetUsers()
    {
        var users = UserManager.Users.ToList();
        return users;
        //return query;
    }
Brad Martin
  • 5,637
  • 4
  • 28
  • 44

2 Answers2

1

Since your using ASP.NET Identity 2, Can you try this instead?

//GET api/Account/AllUsers
[Route("AllUsers")]
public async Task<List<ApplicationUser>> GetUsers()
{
    var users = await UserManager.Users.ToListAsync();
    return users;
}
Jimmy van den Berg
  • 474
  • 1
  • 3
  • 9
  • I don't have ToListAsync() as an option, I tried ToList() which errors : 'await' operator can only be used within an async method. I then tried adding async to the method which ERRORS : 1. return type of an async method must be void, Task or Task<>, 2. Cannot await 'system.collections.generic.list. – Brad Martin May 13 '14 at 15:57
  • Sorry forgot the async and task.. post is edited. Perhaps you could try UserManager.Users.ToList() without await, async and task? – Jimmy van den Berg May 13 '14 at 16:10
  • I tried the above and I'm getting Type conversion errors from IdentityUser to ApplicationUser. When I use the EDIT above I return the IdentityUser values but not the extended properties within ApplicationUser (obviously). However, I need the other properties. Any idea? The ApplicationUser class is also in the original post, that's the information I'm looking to get along with the IdentityUser class info. – Brad Martin May 13 '14 at 16:30
1

you can return Iqueryable USERS list from web api by following way :

   [Route("AllUsers")]
   public IQueryable<User> GetUsers()
    {
       return db.users;
    }
Chandrika Prajapati
  • 867
  • 1
  • 6
  • 11