Quantcast
Channel: ASP.NET Core
Viewing all articles
Browse latest Browse all 9386

Not getting the login user details from my controller

$
0
0

I dont know how can I get the login user details in my controller. from Google I applied the following code but  the error is coming as given below

InvalidOperationException: Unable to resolve service for type 'Microsoft.AspNetCore.Identity.UserManager`1[MetaWeather.Models.ApplicationUser]' while attempting to activate 'MetaWeather.Areas.Customer.Controllers.ForcastController'.

[Area("Customer")]
    [Authorize]
    public class ForcastController : Controller
    {
        private readonly IWeatherRepository _weatherRepository;
        private readonly IUnitOfWork _unitOfWork;
        private readonly UserManager<ApplicationUser> _userManager;

        public Weather Weather { get; set; }
        public ForcastController(IWeatherRepository weatherRepository, IUnitOfWork unitOfWork,
           UserManager<ApplicationUser> userManager)
        {
            _weatherRepository = weatherRepository;
            _unitOfWork = unitOfWork;
            _userManager = userManager;
        }
        public async Task<IActionResult> Index()
        {
           // ApplicationUser applicationUser = await _userManager.GetUserAsync(User);
            var userId = User.FindFirstValue(ClaimTypes.NameIdentifier);
            var user = await _userManager.FindByIdAsync(userId);


Viewing all articles
Browse latest Browse all 9386

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>