Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. ASP.NET
  4. How to access to all the information of a signed-In user stored in User table in ASP.NET Core?

How to access to all the information of a signed-In user stored in User table in ASP.NET Core?

Scheduled Pinned Locked Moved ASP.NET
asp-netdatabasehelpcsharpdotnet
1 Posts 1 Posters 4 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Alex Dunlop
    wrote on last edited by
    #1

    I've created a custom User table using EF Core Identity (registration). Many of these custom columns are True/False values that are filled when the registration of that specific user is done. I have also created a login system that the user enters their username and password to sign in. Now, I want to get access to those information stored in the database for the user signed in successfully and use session to send them to the page. Please help me. Dependancy injection for Home Controller:

    private readonly UserManager _userManager;
    private readonly SignInManager _signInManager;

        public HomeController(UserManager userManager, SignInManager signInManager)
        {
            \_userManager = userManager;
            \_signInManager = signInManager;
        }
    

    Code for Register:

    [HttpPost]
    public async Task Register(RegisterViewModel registerModel)
    {
    DateTime currentDate = DateTime.Now;
    if (ModelState.IsValid)
    {
    var user = new AppUser()
    {
    UserName = registerModel.userName,
    department = registerModel.department,
    creationDate = currentDate,
    isAdmin = registerModel.isAdmin,
    isManager = registerModel.isManager,
    isActive = registerModel.isActive,
    canEdit = registerModel.canEdit,
    canDelete = registerModel.canDelete,
    canSendMessage = registerModel.canSendMessage,
    canSeeNotification = registerModel.canSeeNotification
    };
    var result = await _userManager.CreateAsync(user, registerModel.password);
    if (result.Succeeded)
    {
    await _signInManager.SignInAsync(user, isPersistent: false);
    return RedirectToAction("Privacy", "Home");
    }
    foreach (var error in result.Errors)
    {
    ModelState.AddModelError("", error.Description);
    }
    ModelState.AddModelError(string.Empty, "Invalid Register Attempt");
    }
    return View();
    }

    Code for Login:

    [HttpPost]
    public async Task Index(LoginViewModel user)
    {
    if (ModelState.IsValid)
    {

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups