login user is coming to the variable but cannot be assigned RRS feed

  • Question

  • User-1355965324 posted

    I am trying to get the value of  the login user from the column  IsAuthorised . but when I debug the values is stored in var user but when I try to store the value of isauthorised column  it is not working 

     public class ForcastController : Controller
            private readonly IWeatherRepository _weatherRepository;
            private readonly IUnitOfWork _unitOfWork;
            private readonly UserManager<IdentityUser> _userManager;
            public Weather Weather { get; set; }
            public ForcastController(IWeatherRepository weatherRepository, IUnitOfWork unitOfWork,
               UserManager<IdentityUser> userManager)
                _weatherRepository = weatherRepository;
                _unitOfWork = unitOfWork;
                _userManager = userManager;
            public async Task<IActionResult> Index()
                // ApplicationUser applicationUser = await _userManager.GetUserAsync(User);
                var user = await _userManager.GetUserAsync(User); // The value is stored here while running
    //I cannot get the value from the variable user
    bool isAuth = user.IsAuthorised // IsAuthorised property is not showing . But when I run the value is stored on the variable user
     public class ApplicationUser : IdentityUser
            public string Name { get; set; }
            public string StreetAddress { get; set; }
            public string City { get; set; }
            public string State { get; set; }
            public string PostalCode { get; set; }
            public bool IsAuthorised { get; set; }

    Thursday, June 4, 2020 8:17 PM


  • User475983607 posted

    Try casting the IdentityUser user type to ApplicationUser.

    bool isAuth = ((ApplicationUser)user).IsAuthorised

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, June 4, 2020 8:34 PM