我希望通过SignInManager实现ASP.net身份验证,但不使用EntityFramework。我已经使用SQLClient构建了我自己的数据库层,并且希望只创建使ASP.net身份验证工作所需的任何调用。
我拥有的代码如下(从Startup.cs执行):
// Add EF services to the services container.
services.AddEntityFramework()
.AddSqlServer()
.AddDbContext<OAuthAppDbContext>(opt => opt.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"]));
// Add Identity services to the services container.
services.AddIdentity<ApplicationUser, ApplicationRole>(options =>
{
options.Cookies.ApplicationCookieAuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.AuthenticationScheme = "ApplicationCookie";
options.Cookies.ApplicationCookie.CookieName = "oAuthInterop";
options.Cookies.ApplicationCookie.AutomaticChallenge = true;
options.Cookies.ApplicationCookie.AutomaticAuthenticate = true;
options.Cookies.ApplicationCookie.DataProtectionProvider = new DataProtectionProvider(new DirectoryInfo("d:\\development\\artefacts"),
configure =>
{
configure.SetApplicationName("TestAuthApp");
//configure.ProtectKeysWithCertificate("thumbprint");
});
})
.AddEntityFrameworkStores<OAuthAppDbContext, int>()
.AddDefaultTokenProviders();
并且我需要删除实体框架依赖(并调用我自己的db方法来收集用户详细信息)。还有没有人在ASP.net核心中做过类似的事情?
提前感谢您的指点!:-)
发布于 2016-04-22 20:52:46
至少,您希望以任何您认为合适的方式实现IUserStore、IUserPasswordStore和IRoleStore,并将它们注册到您的IServiceCollection。为了获得完整的身份功能,您可能还需要实现一些其他接口(IUserClaimsStore、IUserPhoneNumberStore、IUserLockoutStore等- you can find the whole list on GitHub)。
最后,不要忘记删除您的EF服务注册!
我已经组装了一个非常基本的内存中示例here。它真的又快又脏,所以我不建议尝试从它中获得太多的灵感。如果你真的想看到一个合适的实现,那就使用here is how the actual EF version is implemented!
https://stackoverflow.com/questions/36794285
复制相似问题