asp.net-identity

How to use DI with UserManager and UserStore

浪尽此生 提交于 2019-12-01 19:05:02
Given a typical setup of a MVC controller constructor passing UserManager (which takes UserStore ) to it's parent class, how would this be converted to be injected via IoC? Starting with this: public AccountController() : this(new UserManager<ApplicationUser>( new UserStore<ApplicationUser>(new ApplicationDbContext()))) { } I would think something like this: public AccountController(IUserStore store) : this(new UserManager<ApplicationUser>(store))) { } Though this does, of course, lose the IdentityDbContext . How should the IoC be setup and how should the constructor be defined to allow

Add column to aspnetusers with database first

余生长醉 提交于 2019-12-01 18:06:33
I have found many tutorials for adding columns to the Identity tables (which I have successfully moved to the application database) with database migrations however my understanding is this is not applicable in database fist projects. So...how do I add columns to the aspnetusers table in a database first project? I would like to ad a bit type column called Is RegComplete which is initially set to 0 then at some point when the user has completed some more tasks then set to 1. OK, I've cracked it! Firstly I didn't realise that although I have moved the Identity tables to the Application database

The INSERT statement conflicted with the FOREIGN KEY constraint error

折月煮酒 提交于 2019-12-01 18:06:23
Hi I'm getting this error The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUsers_dbo.Contacts_ContactID". The conflict occurred in database "aspnet-COGMakati-20140119015553", table "dbo.Contacts", column 'ContactID'. The statement has been terminated. I'm using Entity Framework and MVC 5's IdentityUser so I'm really lost on what I'm doing :| This is what I'm trying to populate: public class User : IdentityUser { [Required] [Display(Name = "First Name")] public string FirstName { get; set; } [Required] [Display(Name = "Last Name")] public string LastName { get; set;

asp.net-identity transaction issue

百般思念 提交于 2019-12-01 18:05:20
I want to create a user with a role in the same transaction but i have an issue with the implementation. In order to use the userStore in the transaction and have it not save the changes automatically and ignore my transaction i had to turn off AutoSaveChanges. This makes it so it will wait until i call save changes. This works fine but because the userstore now does not return the userId when i call manager.Create due to this being off I dont have an Id to pass into userManager.AddToRole. Is there any way to add the user i am trying to create to a role within the same transaction? If you

Customised IdentityUserRole primary key

此生再无相见时 提交于 2019-12-01 17:58:23
I'm using ASP.NET Identity Provider and EF 6 Code First and I have created a custom IdentityUserRole table which has an extra column OrganisationId . The custom table is named UserRole. The table currently has the default primary key of UserId and RoleId . I would like to have the OrganisationId column included in the Primary Key of the IdentityUserRole table. I can see the UserRole table in my database, and it's the one that's being used for the userroles (there's no aspnet_userrole table and the table has data when I assign a role to a user) I tried this: modelBuilder.Entity<IdentityUserRole

How to Authenticate using MVC5RC/RTW with existing database

淺唱寂寞╮ 提交于 2019-12-01 17:27:48
问题 I originally asked this question when Identity was in beta. The classes and interfaces have changed considerably since then and it appears the RTW version has some modifications again over the RC version. In principle I need to achieve the following. authenticate the local login against my usertable tblMembers which contains the userid field and password which are the two items I need to authenticate. have access to my tblMember record/class via the Controller.User property (Prior to MVC5

The INSERT statement conflicted with the FOREIGN KEY constraint error

…衆ロ難τιáo~ 提交于 2019-12-01 16:41:32
问题 Hi I'm getting this error The INSERT statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUsers_dbo.Contacts_ContactID". The conflict occurred in database "aspnet-COGMakati-20140119015553", table "dbo.Contacts", column 'ContactID'. The statement has been terminated. I'm using Entity Framework and MVC 5's IdentityUser so I'm really lost on what I'm doing :| This is what I'm trying to populate: public class User : IdentityUser { [Required] [Display(Name = "First Name")] public

AspNet Core Identity, how set options.Cookie.SameSite?

左心房为你撑大大i 提交于 2019-12-01 16:25:12
In the latest templates and libraries used httpsonly flag. How can I turn it off? This same question is outdated and it did not have full configuration sample: AspNet Core Identity - cookie not getting set in production In order to configure the application cookie when using Identity, you can use the ConfigureApplicationCookie method inside your Startup’s ConfigureServices : // add identity services.AddIdentity<ApplicationUser, IdentityRole>(); // configure the application cookie services.ConfigureApplicationCookie(options => { options.Cookie.SameSite = SameSiteMode.None; }); Since Identity

Owin Authentication.SignIn not working

我是研究僧i 提交于 2019-12-01 16:21:06
I try to use owin authentication manager to authenticate users but User.Identity.IsAuthenticated is still false. Startup.cs public partial class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } Startup.Auth.cs public partial class Startup { public static Func<UserManager<ApplicationUser>> UserManagerFactory { get; set; } public Startup() { UserManagerFactory = () => { var userManager = new UserManager<ApplicationUser>(new CustomUserStore()); return userManager; }; } public void ConfigureAuth(IAppBuilder app) { app.UseCookieAuthentication(new

Owin Authentication.SignIn not working

孤者浪人 提交于 2019-12-01 16:19:15
问题 I try to use owin authentication manager to authenticate users but User.Identity.IsAuthenticated is still false. Startup.cs public partial class Startup { public void Configuration(IAppBuilder app) { app.MapSignalR(); } } Startup.Auth.cs public partial class Startup { public static Func<UserManager<ApplicationUser>> UserManagerFactory { get; set; } public Startup() { UserManagerFactory = () => { var userManager = new UserManager<ApplicationUser>(new CustomUserStore()); return userManager; };