我尝试从头开始使用 ASP.net Identity 编写 MVC 应用程序。 为此,我遵循了 Ben Foster 的两个教程(Tutorial Part1 和 Tutorial Part2)
但我停留在第二个教程 - 配置 UserManager。以下行对我不起作用:
// configure the user manager
UserManagerFactory = () =>
{
var usermanager = new UserManager<AppUser>(
new UserStore<AppUser>(new AppDbContext()));
...
}
Visual Studio 下划线
new AppDbContext()
并向我显示以下消息:
Argument type "MyProject.DbContext.AppDbContext" is not assignable to parameter type "System.Data.Entity.DbContext"
我不明白为什么它在我的解决方案中不起作用,因为我完全遵循了教程。我的 AppDbContext 看起来像:
namespace MyProject.DbContext
{
using MyProject.Models;
using Microsoft.AspNet.Identity.EntityFramework;
public class AppDbContext : IdentityDbContext<User>
{
public AppDbContext()
: base("DefaultConnection")
{
}
}
}
我的用户类:
namespace MyProject.Models
{
using Microsoft.AspNet.Identity.EntityFramework;
public class User : IdentityUser
{
public string Name{ get; set; }
}
}
我还从 Ben 下载了源代码并尝试运行它,它没有任何问题。我认为我的所有文件都不在同一个文件夹中没有任何区别?!
我希望你能帮助我。如果一个简单的教程不能正常工作,那真的很令人沮丧......
问候,winklerrr
最佳答案
我通过删除所有与 owin 和 ASP.net Identity 有关的引用并重新添加它们来解决问题。
我认为,问题是由引用的 dll 和实际使用的 dll 之间的差异引起的...(在包管理器控制台上玩了很多。)
关于c# - 参数类型不能分配给参数类型,尽管它继承,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25832464/