在ASP.NET Identity中,有时可能会遇到“ASP.NET Identity无法转换为IUserStore”的错误。这个错误通常是因为没有正确配置Identity的用户存储。
以下是一个解决方法的示例代码:
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
protected void Application_Start()
{
// ...
ApplicationDbContext context = new ApplicationDbContext();
UserStore userStore = new UserStore(context);
UserManager userManager = new UserManager(userStore);
// ...
}
using Microsoft.AspNet.Identity;
using Microsoft.AspNet.Identity.EntityFramework;
public class ApplicationUserManager : UserManager
{
public ApplicationUserManager(IUserStore store)
: base(store)
{
}
public static ApplicationUserManager Create(IdentityFactoryOptions options, IOwinContext context)
{
// ...
ApplicationDbContext dbContext = context.Get();
ApplicationUserManager userManager = new ApplicationUserManager(new UserStore(dbContext));
// ...
}
}
Update-Database
这些是一个可能的解决方法的示例代码。根据你的具体情况,可能需要进行一些调整。但是,确保正确配置和设置Identity的用户存储通常可以解决这个问题。