c# - 如何在没有 EntityFramework 的情况下使用 ASP.net Core 1 "SignInManager"

标签 c# asp.net asp.net-mvc entity-framework

我希望通过 SignInManager 但没有 EntityFramework 来实现 ASP.net 身份验证。我已经使用 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();

并且我需要删除 Entity Framework 依赖(并调用我自己的数据库方法来收集用户详细信息)。有没有其他人在 ASP.net Core 中做过类似的事情?

在此先感谢您的指点! :-)

最佳答案

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

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

我整理了一个非常基本的内存示例 here .它真的又快又脏,所以我不建议尝试从中获取太多灵感。如果你真的想看到一个正确的实现,here is how the actual EF version is implemented !

关于c# - 如何在没有 EntityFramework 的情况下使用 ASP.net Core 1 "SignInManager",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36794285/

相关文章:

c# - 打开/关闭编译器优化标志的CPU密集型应用程序

javascript - 如何更改javascript函数中的标签文本?

asp.net-mvc - 我如何在 AreaRegistration 中使用 ninject

c# - 具有过滤 dbContext 的 Multi-Tenancy Web 应用程序

c# - 如何从 XDocument 获取 Xml 作为字符串?

c# - 如何在 windows 8 Apps 中获取 webview 的当前 URL | C#、XMAL

c# - 跨多个项目共享 Entity Framework 库

asp.net - 我可以确定 HttpModules 是按照它们在 HttpApplication.Modules 集合中列出的顺序执行的吗?

asp.net-mvc - 有没有人知道让 Ninject 2 在 ASP.NET MVC 中工作的好指南?

c# - C#动态获取类元素的方法