Rob*_*abe 23 c# asp.net asp.net-mvc entity-framework
我想通过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();
Run Code Online (Sandbox Code Playgroud)
我需要删除实体框架依赖(并调用我自己的数据库方法来收集用户详细信息).有没有其他人在ASP.net核心做过类似的事情?
提前感谢任何指针!:-)
Mat*_*ing 42
至少,您需要以您认为合适的任何方式实现IUserStore <ApplicationUser>,IUserPasswordStore <ApplicationUser>和IRoleStore <ApplicationUser>,并将它们与您的IServiceCollection一起注册.您可能需要实现一些其他接口来获取完整的身份功能(IUserClaimsStore,IUserPhoneNumberStore,IUserLockoutStore等 - 您可以在GitHub上找到整个列表).
最后,不要忘记删除您的EF服务注册!
我已经把一个非常基本的内存例子在这里.这真的很快,很脏,所以我不建议尝试从中获取太多灵感.如果你真的想看到一个正确的实现,这里是实际的EF版本的实现方式!
| 归档时间: |
|
| 查看次数: |
9103 次 |
| 最近记录: |