首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何在没有EntityFramework的情况下使用ASP.net核心1 "SignInManager“

如何在没有EntityFramework的情况下使用ASP.net核心1 "SignInManager“
EN

Stack Overflow用户
提问于 2016-04-22 20:47:56
回答 1查看 11K关注 0票数 23

我希望通过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核心中做过类似的事情?

提前感谢您的指点!:-)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2016-04-22 20:52:46

至少,您希望以任何您认为合适的方式实现IUserStoreIUserPasswordStoreIRoleStore,并将它们注册到您的IServiceCollection。为了获得完整的身份功能,您可能还需要实现一些其他接口(IUserClaimsStore、IUserPhoneNumberStore、IUserLockoutStore等- you can find the whole list on GitHub)。

最后,不要忘记删除您的EF服务注册!

我已经组装了一个非常基本的内存中示例here。它真的又快又脏,所以我不建议尝试从它中获得太多的灵感。如果你真的想看到一个合适的实现,那就使用here is how the actual EF version is implemented

票数 42
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/36794285

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档