D
D
DenisVladimirovich2019-07-21 01:13:06
ASP.NET
DenisVladimirovich, 2019-07-21 01:13:06

How to display user data in Layout?

Good evening gentlemen. I've been struggling with this problem for some time now. The point is this. I'm not a pro in ASP, so I'm asking you. I can't get user data inside the Layout of the page.
Tried in different ways. For example, this method did not work

@using Microsoft.AspNetCore.Identity
@using KSM_Agro.Models
@inject SignInManager<User> SignInManager
@inject UserManager<User> UserManager

@{
    var user = await UserManager.GetUserAsync(User);

}

It always gives me an error that I don't have an IServiceProvider registered.
I'll ask right away. You should not be advised to pass user data through ViewBag or similar tools. I need to take exactly from Layout. Esteemed that it is necessary to add in a configuration through services.AddSingleton or AddTransient. But both throw the same error No service for type 'Microsoft.AspNetCore.Identity.UserManager`[WebApp.Models.User]' has been registered.
I understand what he writes, but at the same time he carried out the registration. I don't know what to do gentlemen.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
Dmitry, 2019-07-21
@fgon

Show registration. You also write that the type is not registered.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question