当我第一次打电话到我的网页api时
GetAssignedRoles/{userID}
它第一次有效。后续调用返回相同的结果集,直到我再次调用此方法之前调用另一个方法
[HttpGet("GetAssignedRoles/{userID}")]
public async Task<IActionResult> GetAssignedRoles(string userID)
{
ApplicationUser user = await _userManager.FindByIdAsync(userID);
IList<string> roles = await _userManager.GetRolesAsync(user);
List<UserRole> userRoles = new List<UserRole>();
foreach(var item in roles)
{
userRoles.Add(await _roleManager.FindByNameAsync(item));
}
IEnumerable<UserRoleViewModel> roleViewModel = Mapper.Map<IEnumerable<UserRole>, IEnumerable<UserRoleViewModel>>(userRoles);
return new OkObjectResult(roleViewModel);
}