Results 1 to 2 of 2

Thread: Getting the ApplicationUser object in a controller

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Sep 2008
    Posts
    1,260

    Getting the ApplicationUser object in a controller

    I am writing a C# MVC5 internet application and am having some trouble getting the 'ApplicationUser' object in a controller that I have created.

    Here is my code:

    Code:
    var userManager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext()));
    ApplicationUser user = userManager.FindByNameAsync(User.Identity.GetUserId()).Result;
    When I try to run this code, when a user is logged in, I am getting a null object for the 'ApplicationUser' user.

    Can I please have some help with this?

    Thanks in advance

  2. #2
    Frenzied Member KGComputers's Avatar
    Join Date
    Dec 2005
    Location
    Cebu, PH
    Posts
    2,020

    Re: Getting the ApplicationUser object in a controller

    Try passing the Name property instead of user id.
    csharp Code:
    1. userManager.FindByNameAsync(User.Identity.Name).Result;

    FindByNameAsync Method
    CodeBank: VB.NET & C#.NET | ASP.NET
    Programming: C# | VB.NET
    Blogs: Personal | Programming
    Projects: GitHub | jsFiddle
    ___________________________________________________________________________________

    Rating someone's post is a way of saying Thanks...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width