ASP.NET Identity 3.0의 컨트롤러에서 응용 프로그램 사용자를 얻으려면 googleing을 사용하고 있지만 결과는 5 이하입니다.컨트롤러에서 ApplicationUar 가져 오기
ApplicationUser
속성을 얻으려고하고 있지만 ApplicationUser
을 전혀 가져올 수 없습니다. 나는이 문제가있는 유일한 사람이기 때문에 쉽습니다.
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNet.Mvc;
using Microsoft.AspNet.Mvc.Rendering;
using Microsoft.Data.Entity;
using System;
using System.Collections.Generic;
using System.Reflection;
using Microsoft.AspNet.Identity;
using System.Security.Claims;
namespace ApplicationUserFMLTest.Controllers
{
public class CustomClassController : Controller
{
private readonly UserManager<ApplicationUser> _userManager;
private readonly SignInManager<ApplicationUser> _signInManager;
private ApplicationDbContext _context;
public CandidatesController(ApplicationDbContext context, UserManager<ApplicationUser> userManager, SignInManager<ApplicationUser> signInManager)
{
_context = context;
_userManager = userManager;
_signInManager = signInManager;
}
// GET: CustomClass
public async Task<IActionResult> Index()
{
ApplicationUser currentUser = _userManager.FindByIdAsync(User.Identity.GetUserId()).Result;
if (currentUser.PropBool)
return View(currentUser);
return View();
}
// ManageController function
private async Task<ApplicationUser> GetCurrentUserAsync()
{
return await _userManager.FindByIdAsync(HttpContext.User.GetUserId());
}
}
}
코드에 문제가 있습니까? 오류가 있었습니까? –
Identity에 'GetUserId'에 대한 정의가없고 최상단 확장 메서드가 포함되어 있지 않습니다. ovreload 'PrincipalExtensions.GetUserId (ClaimsPrincipal)'에는 'ClaimsPrincipal'유형의 수신기가 필요합니다. – StuiterSlurf