How can I change the table names when using ASP.NET Identity?

You can do this easily by modifying the IdentityModel.cs as per the below: Override OnModelCreating in your DbContext then add the following, this will change AspNetUser table to “Users” you can also change the field names the default Id column will become User_Id. modelBuilder.Entity<IdentityUser>() .ToTable(“Users”, “dbo”).Property(p => p.Id).HasColumnName(“User_Id”); or simply the below if you want … Read more

ASP.NET MVC 5 – Identity. How to get current ApplicationUser

You should not need to query the database directly for the current ApplicationUser. That introduces a new dependency of having an extra context for starters, but going forward the user database tables change (3 times in the past 2 years) but the API is consistent. For example the users table is now called AspNetUsers in … Read more

How to get the current logged in user ID in ASP.NET Core?

Update in ASP.NET Core Version >= 2.0 In the Controller: public class YourControllerNameController : Controller { private readonly UserManager<ApplicationUser> _userManager; public YourControllerNameController(UserManager<ApplicationUser> userManager) { _userManager = userManager; } public async Task<IActionResult> YourMethodName() { var userId = User.FindFirstValue(ClaimTypes.NameIdentifier) // will give the user’s userId var userName = User.FindFirstValue(ClaimTypes.Name) // will give the user’s userName // For … Read more

ASP.NET Identity – HttpContext has no extension method for GetOwinContext

ARGH! I found it… I didn’t have an extra package, called Microsoft.Owin.Host.SystemWeb Once i searched and installed this, it worked. Now – i am not sure if i just missed everything, though found NO reference to such a library or package when going through various tutorials. It also didn’t get installed when i installed all … Read more

tech