asp.net-identity

Identity UserManager.AddToRole throws exception

只谈情不闲聊 提交于 2019-12-06 13:07:59
问题 As the title says I am using the new C# MVC 5 Identity doing a simple call: UserManager.AddToRole(User.Id, User.RequestedRole); I am doing this in a method of my ViewModel that is called from the Controller The UserManager is created in the Base Class of my ViewModel like this: UserManager = new UserManager<TMUser>(new UserStore<TMUser>(new TMContext())); When I make the above call to AddToRole method, I get this Inner Exception (The outer one is generic/useless): {"A relationship from the

Identity Server 4, EF Core, share DbContext between API and IS4

依然范特西╮ 提交于 2019-12-06 12:49:20
问题 I'm using Identity Server 4, Asp Identity, EF Core and one database. I have 3 projects at the moment IdentityServer - Contains all data contexts and all migrations with my app tables Api - no context, no migrations however I need to access database somehow from here Clinet - javascript The question: How do I access data context from IdentityServer project and still have all settings (db connection, etc) in one place. I understand I can reference IdentityServer from API and use data context

Why is User.Identity null after login with AspNet.Identity 3.0

末鹿安然 提交于 2019-12-06 12:45:53
问题 I am using Microsofts AspNet.Identity 3.0 framework within the DNX RC1. With the help of some tutorials I have built a custom authentication system. After a successful password check some claims are created for the user and the Authentication will be set: var claimsPrincipal = await SignInManager.CreateUserPrincipalAsync(user); if (claimsPrincipal != null && claimsPrincipal.Identity != null) { // Set the claims to the user await HttpContext.Authentication.SignInAsync

Invalid object name 'dbo.AspNetUsers'

妖精的绣舞 提交于 2019-12-06 12:42:56
I have an MVC5 application using Entity Framework 6.1 and Asp.Net Identity 2 and have data migrations enabled. I have used sample code from other answers on StackExchange to seed the Role and User tables. My application data context is based on IdentityDbContext. On issuing an update-database command, my database is created and populated with the following tables: My app launches OK, but when I try to log in using the seeded user (or any user for that matter), I get the following error: How can I get SignInManager to reference the IdentityUsers table instead of AspNetUsers? You can set custom

Combine my ApplicationsDbContext with IdentityDbContext no key defined using MVC 5

断了今生、忘了曾经 提交于 2019-12-06 12:37:22
I was combining my existing DBContext with the new IdentityDbContext in MVC 5. I managed to combine the two contexts but when I ran my application and the model was being created I was presented with the following error message: Context.IdentityUserLogin: : EntityType 'IdentityUserLogin' has no key defined. Define the key for this EntityType. Context.IdentityUserRole: : EntityType 'IdentityUserRole' has no key defined. Define the key for this EntityType. I worked out how to fix it after doing a bit of reading. Create the two following configuration classes (keeps it clean in your

How to delete user with UserManager in mvc5

流过昼夜 提交于 2019-12-06 11:19:14
I'm using mvc5, and everything about user account management I do with UserManager. It works good with roles, claims, etc. But I didn't find how to delete user with UserManager. Is there a way to delete user with UserManager? I can create Database context with dbset and then delete it from this context, but I don't want create dbcontext, userclass, etc. for one delete method. Delete was not supported in UserManager in 1.0, but its supported in the upcoming 2.0 release, and in the current 2.0 nightly builds if you want to preview the changes early. I had issues with the above answer, though I

Error: “The Id field is required.” while registering new user in database with AspNet.Identity 2.0

隐身守侯 提交于 2019-12-06 09:40:17
Welcome, I get the validation error mentioned in topic while creating (registering) new user in my Asp.Net mvc application where I used Asp.Net Identity with my custom ApplicationUser class public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim> { public async Task<ClaimsIdentity> GenerateUserIdentityAsync(ApplicationUserManager manager) { var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); return userIdentity; } public virtual string EmailConfirmedChar { get; set; } public

Save tokens in Cookie with ASP.NET Core Identity

こ雲淡風輕ζ 提交于 2019-12-06 08:38:15
I want to save something inside my 'Identity' generated cookie. I'm currently using the default Identity setup from the Docs. Startup.cs services.Configure<IdentityOptions>(options => { // User settings options.User.RequireUniqueEmail = true; // Cookie settings options.Cookies.ApplicationCookie.AuthenticationScheme = "Cookies"; options.Cookies.ApplicationCookie.ExpireTimeSpan = TimeSpan.FromHours(1); options.Cookies.ApplicationCookie.SlidingExpiration = true; options.Cookies.ApplicationCookie.AutomaticAuthenticate = true; options.Cookies.ApplicationCookie.LoginPath = "/Account"; options

Correlation failed. at Microsoft.AspNetCore.Authentication.RemoteAuthenticationHandler during OIDC authentication

天涯浪子 提交于 2019-12-06 08:26:24
I am hitting this with the following combination: 1) Browser incognito mode (Chrome) 2) Application is behind Azure application gateway (no repro if it isnt). Cookie based affinity is turned OFF (default); if turned ON, seems to make repro happen more often. Code is rather plain vanilla OIDC authN + cookies. services.AddAuthentication(options => { options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme; options.DefaultChallengeScheme = OpenIdConnectDefaults.AuthenticationScheme; }) .AddAzureAd(options => { Configuration.Bind("AzureAd", options); }) .AddCookie(p => p

Checking role exists for user before add

徘徊边缘 提交于 2019-12-06 07:39:32
问题 I am trying to add roles for user but before that i want to check it is exists or not. How Can i do that? Here is my code public void AddRoleForUser(ApplicationUser obj, IdentityRole role) { _userManager = new ApplicationUserManager(new UserStore<ApplicationUser>(_context)); var currentUser = _userManager.FindById(obj.Id); // before this i have to check var roleresult = _userManager.AddToRole(currentUser.Id, role.Name); } for example i have a user and its id =1. When i add role for this user