How to localize ASP.NET Identity UserName and Password error messages?

For ASP.NET Core: (Microsoft.AspNetCore.Identity 1.0.0) Create a class that inherits IdentityErrorDescriber and override the desired error messages. public class CustomIdentityErrorDescriber : IdentityErrorDescriber { public override IdentityError DefaultError() { return new IdentityError { Code = nameof(DefaultError), Description = $”An unknown failure has occurred.” }; } public override IdentityError ConcurrencyFailure() { return new IdentityError { Code = … Read more

ASP.NET Identity with EF Database First MVC5

It should be possible to use the identity system with POCO and Database First, but you’ll have to make a couple of tweaks: Update the .tt-file for POCO generation to make the entity classes partial. That will make it possible for you to supply additional implementation in a separate file. Make a partial implementation of … Read more

Creating Roles in Asp.net Identity MVC 5

Here we go: var roleManager = new RoleManager<Microsoft.AspNet.Identity.EntityFramework.IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext())); if(!roleManager.RoleExists(“ROLE NAME”)) { var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole(); role.Name = “ROLE NAME”; roleManager.Create(role); }

ASP.NET Core Identity – get current user

If your code is inside an MVC controller: public class MyController : Microsoft.AspNetCore.Mvc.Controller From the Controller base class, you can get the ClaimsPrincipal from the User property System.Security.Claims.ClaimsPrincipal currentUser = this.User; You can check the claims directly (without a round trip to the database): bool isAdmin = currentUser.IsInRole(“Admin”); var id = _userManager.GetUserId(User); // Get user … Read more

ASP.NET Identity reset password

Or how can I reset without knowing the current one (user forgot password)? If you want to change a password using the UserManager but you do not want to supply the user’s current password, you can generate a password reset token and then use it immediately instead. string resetToken = await UserManager.GeneratePasswordResetTokenAsync(model.Id); IdentityResult passwordChangeResult = … Read more

What is the advantage of using async with MVC5?

The async actions are useful only when you are performing I/O bound operations such as remote server calls. The benefit of the async call is that during the I/O operation, no ASP.NET worker thread is being used. So here’s how the first example works: When a request hits the action, ASP.NET takes a thread from … Read more

How to extend available properties of User.Identity

Whenever you want to extend the properties of User.Identity with any additional properties like the question above, add these properties to the ApplicationUser class first like so: public class ApplicationUser : IdentityUser { public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) { // Note the authenticationType must match the one defined in CookieAuthenticationOptions.AuthenticationType var userIdentity = await manager.CreateIdentityAsync(this, … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)