0

此代碼用於在數據庫中創建角色。無法從'方法組'轉換爲'Func <ApplicationRoleManager>在asp mvc身份

IdentityConfig:

public class ApplicationRoleManager : RoleManager<IdentityRole> 
{ 
    public ApplicationRoleManager(RoleStore<IdentityRole> roleStore) 
     : base(roleStore) 
    { 
    } 

    public static ApplicationRoleManager Create(IOwinContext context) 
    { 
     var roleStore = new RoleStore<IdentityRole>(context.Get<ApplicationDbContext>()); 
     return new ApplicationRoleManager(roleStore); 
    } 
} 

但Startup.Auth告訴我錯誤:

enter image description here

我該如何解決這個問題?

編輯

public void Configuration(IAppBuilder app) 
{ 
    ConfigureAuth(app); 
} 
+0

我看到你的錯誤來自於auth配置,請在'Startup'類中'ConfigureAuth'方法顯示任何相關的代碼。 –

+0

更新問題 – Kianoush

回答

1

簽名CreatePerOwingContext<T>看起來是這樣的:

public static IAppBuilder CreatePerOwinContext<T>(this IAppBuilder app, Func<IdentityFactoryOptions<T>, IOwinContext, T> createCallback) where T : class, IDisposable 

或像這樣:

public static IAppBuilder CreatePerOwinContext<T>(this IAppBuilder app, Func<T> createCallback) where T : class, IDisposable 

即你以太需要提供一個功能,將創建一個對象,即

app.CreatePerOwinContext<ApplicationRoleManager>(() => new ApplicationRoleManager(/*blah params*/)); 

這將使用第二個覆蓋。或者回到默認值:

public static ApplicationRoleManager Create(IdentityFactoryOptions<ApplicationRoleManager> options, IOwinContext context) 
{ 
    var applicationDbContext = context.Get<ApplicationDbContext>(); 
    var roleStore = new RoleStore<IdentityRole>(applicationDbContext); 
    var manager = new ApplicationRoleManager(roleStore); 

    return manager; 
}  
相關問題