asp.net-identity-2

How to inject User Manager to Account Controller with default Identity Model in Identity 2 using Ninject

末鹿安然 提交于 2019-12-02 05:54:00
问题 I use Ninject on a MVC 5 project with Identity 2. For rest of data context and controllers using that I have no problems with dependency injection. For Account controller that uses Identity 2 model I'm getting null UserManager when I try to login: public class AccountController : Controller { private ApplicationUserManager _userManager; public AccountController() { } public AccountController(ApplicationUserManager userManager) { UserManager = userManager; } public ApplicationUserManager

Add relationships to the ApplicationUser class in ASP.NET Identity (Database First)

依然范特西╮ 提交于 2019-12-01 23:43:02
问题 I'm using ASP.NET Identity (Database First) in my ASP.NET MVC application. I followed the instructions here, to set up the ASP.NET Identity with database first approach. My AspNetUsers table has a relationship with the Employee table (The Employee table has a UserId foreign key, and the AspNetUsers entity has an ICollection<Employee> property). I would like to add the ICollection<Employee> property to the ApplicationUser, like below: public class ApplicationUser : IdentityUser<int,

Moving Identity 2.0 functions to repository class

痴心易碎 提交于 2019-12-01 22:56:01
问题 I am using identity 2.0 for my application and want to move the data functionalities to repository layer such as the following code: public class ApplicationDbInitializer : DropCreateDatabaseIfModelChanges<ApplicationDbContext> { protected override void Seed(ApplicationDbContext context) { InitializeIdentityForEF(context); base.Seed(context); } //Create User=Admin@Admin.com with password=Admin@123456 in the Admin role public static void InitializeIdentityForEF(ApplicationDbContext db) { var

Moving Identity 2.0 functions to repository class

情到浓时终转凉″ 提交于 2019-12-01 22:11:54
I am using identity 2.0 for my application and want to move the data functionalities to repository layer such as the following code: public class ApplicationDbInitializer : DropCreateDatabaseIfModelChanges<ApplicationDbContext> { protected override void Seed(ApplicationDbContext context) { InitializeIdentityForEF(context); base.Seed(context); } //Create User=Admin@Admin.com with password=Admin@123456 in the Admin role public static void InitializeIdentityForEF(ApplicationDbContext db) { var userManager = HttpContext.Current.GetOwinContext().GetUserManager<ApplicationUserManager>(); var

Using MVC 5's identity, can't get user name right after logging in

我的未来我决定 提交于 2019-12-01 16:23:30
I'm trying to use the MVC 5's identity solution, but got stuck on something that should be very simple: I want the login method on the AccountController to get the loged user's name right after validating the model (and I don't want to use it from the model!). Here's a piece of my code: var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, false, shouldLockout: false); string NomeUsuario = ""; if (result == SignInStatus.Success) { NomeUsuario = User.Identity.Name; //<== getting the logged user's name } The problem that I'm getting is that this property is null.

Using MVC 5's identity, can't get user name right after logging in

核能气质少年 提交于 2019-12-01 15:00:47
问题 I'm trying to use the MVC 5's identity solution, but got stuck on something that should be very simple: I want the login method on the AccountController to get the loged user's name right after validating the model (and I don't want to use it from the model!). Here's a piece of my code: var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, false, shouldLockout: false); string NomeUsuario = ""; if (result == SignInStatus.Success) { NomeUsuario = User.Identity.Name;

Invalidate ClaimsPrincipal after it has been modified

故事扮演 提交于 2019-12-01 14:21:17
I am using ASP.NET MVC, Identity2. I have added "FirstName" Custom ClaimPrincipal : public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, long> manager) { var userIdentity = await manager.CreateIdentityAsync( this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("FirstName", FirstName)); return userIdentity; } If I update the value of "FirstName", I need to logout and log back in, for the "FirstName" Claim to be updated. Is it possible to invalidate "FirstName" Claim, so it's value is forced to be

Invalidate ClaimsPrincipal after it has been modified

自古美人都是妖i 提交于 2019-12-01 13:21:14
问题 I am using ASP.NET MVC, Identity2. I have added "FirstName" Custom ClaimPrincipal : public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser, long> manager) { var userIdentity = await manager.CreateIdentityAsync( this, DefaultAuthenticationTypes.ApplicationCookie); // Add custom user claims here userIdentity.AddClaim(new Claim("FirstName", FirstName)); return userIdentity; } If I update the value of "FirstName", I need to logout and log back in, for the

Two questions about MVC, and Identity

混江龙づ霸主 提交于 2019-12-01 12:39:15
问题 I am very new to identity and MVC, I am trying to create an MVC app as one of my first projects. I have been able to follow a few tutorials and have successfully added additional properties to my ApplicationUser : IdentityUser class public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { [Required] [Display(Name = "UserName")] [StringLength(50)] public string Handle { get; set; } [StringLength(100, ErrorMessage = "Your {0} can be

ASP.NET Identity + Facebook login: Pass in “rerequest?”

一世执手 提交于 2019-12-01 12:29:48
问题 (Using ASP.NET Identity 2.1, Microsoft.Owin.Security.Facebook 3.0.1 in a Web API project) From here: https://developers.facebook.com/docs/facebook-login/login-flow-for-web/v2.2 This is because once someone has declined a permission, the Login Dialog will not re-ask them for it unless you explicitly tell the dialog you're re-asking for a declined permission. You do this by adding the auth_type: rerequest flag to your FB.login() call: FB.login( function(response) { console.log(response); }, {