![](/img/trans.png)
[英]KendoUI Cascading Dropdowns — Retrieving json data from dropdown to use in controller
[英]Retrieving data from classes that use TPH in entityframework
因此,我使用身份腳手架開始了我的項目,並創建了一個從身份用戶繼承的應用程序用戶 class
using Microsoft.AspNetCore.Identity;
namespace test6.Models
{
public class ApplicationUser : IdentityUser
{
public string FirstName { get; set; }
public string LastName { get; set; }
}
}
和一些繼承自這個 class 的類
using Microsoft.AspNetCore.Identity;
namespace test6.Models
{
public class Teacher : ApplicationUser
{
public string Course { get; set; }
}
}
我已經設置了我的角色,它們似乎工作正常,但我的問題是我正在嘗試從用戶檢索數據,並且在檢索特定於從 applicationuser 繼承的 class 的數據時,如 Course from Teacher 我得到一個錯誤這是因為我的用戶管理器是用 ApplicationUser 初始化的
private readonly UserManager<ApplicationUser> _userManager;
我用來檢索用戶的方法是這樣的
[HttpGet]
public async Task<IActionResult> ListTeacher()
{
var users = await _userManager.GetUsersInRoleAsync("Teacher");
return View(users);
}
因此,我嘗試用 Teacher 初始化 usermanager 進行測試,但我收到一個錯誤,我認為這是因為在依賴項中我使用了 ApplicationUser,我認為你不能使用多個。 所以我的問題是有什么可能的解決方案。(抱歉,如果我的問題不是很好或者我的解釋很差)
好的,我想我已經找到了解決方案,事實證明您可以添加另一個依賴項。
builder.Services.AddIdentityCore<Teacher>()
.AddRoles<IdentityRole>()
.AddClaimsPrincipalFactory<UserClaimsPrincipalFactory<Teacher, IdentityRole>>()
.AddEntityFrameworkStores<ApplicationDbContext>()
.AddDefaultTokenProviders()
.AddDefaultUI();
有了這個,我可以用 Teacher 初始化 usermanager,到目前為止它已經工作了。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.