我正在嘗試向我的應用程式添加角色功能,但我收到一條錯誤訊息,我不太了解或不知道如何修復它。
我試圖將 IdentityRole 添加到 services.AddIdentityCore 但收到一條錯誤訊息:
“‘IServiceCollection’不包含‘AddIdentityCore’的定義,并且找不到接受‘IServiceCollection’型別的第一個引數的可訪問擴展方法‘AddIdentityCore’(您是否缺少 using 指令或程式集參考?)[API]csharp (CS1061)

有誰知道如何正確實施它?什么原因導致這個問題?非常感謝你的幫忙
uj5u.com熱心網友回復:
解決方法很簡單。試試這個代碼,如下所示:-
您的AppUser.cs型號:-
public class AppUser:IdentityUser
{
...
}
您的startup.cs檔案:-
services.AddIdentity<AppUser, IdentityRole>(options=> {
options.Password.RequireDigit = false;
...
})
.AddEntityFrameworkStores<DataContext>()
.AddDefaultTokenProviders();
嘗試與上面完全相同的代碼。它將解決您的問題。
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/353970.html
