How to make EF-Core use a Guid instead of String for its ID/Primary key

You need custom ApplicationUser inherit from IdentityUser<TKey> and custom Role inherit from IdentityRole<TKey> public class ApplicationUser : IdentityUser<Guid> { } public class Role : IdentityRole<Guid> { } Custom context class inherit from IdentityDbContext<ApplicationUser, Role, TKey> and use fluent api for auto generate guid keys. public class ApplicationDbContext : IdentityDbContext<ApplicationUser, Role, Guid> { protected override void … Read more

How do you login/authenticate a user with Asp.Net MVC5 RTM bits using AspNet.Identity?

So here’s what login will basically look like in RTM (code copied from the ASPNET Identity sample code): // // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (ModelState.IsValid) { var user = await UserManager.FindAsync(model.UserName, model.Password); if (user != null) { await SignInAsync(user, model.RememberMe); return RedirectToLocal(returnUrl); } else { … Read more

ASP.NET Identity Cookie across subdomains

In Startup.Auth.cs, you will see something like: for RC: app.UseSignInCookies(); This was removed in RTM and replaced with the explicit configuration of the cookie auth: app.UseCookieAuthentication(new CookieAuthenticationOptions { AuthenticationType = DefaultAuthenticationTypes.ApplicationCookie, LoginPath = new PathString(“/Account/Login”) }); The CookieAuthenticationOptions class has a CookieDomain property which is what you are looking for I believe.

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 UserName to Email

If you really want to use e-mail address to log in, then, IMHO, the “hack” you suggested is the best approach. Because, if you insist on “doing it properly” you’ll have to at least modify the database schema, obviously ensure username uniqueness yourself (you could make a database constraint/index do this for you, but you’ll … Read more

ASP.NET Core MVC: setting expiration of identity cookie

The ASP.NET Identity middleware which you are using is a wraper around some calls to UseCookieAuthentication which includes the Cookie Authentication middleware on the pipeline. This can be seen on the source code for the builder extensions of the Identity middleware here on GitHub. In that case the options needed to configure how the underlying … Read more

ExpireTimeSpan ignored after regenerateIdentity / validateInterval duration in MVC Identity (2.0.1)

When the SecurityStampValidator fires the regenerateIdentity callback, the currently authenticated user gets re-signed in with a non-persistent login. This is hard-coded, and I don’t believe there is any way to directly control it. As such, the login session will continue only to the end of the browser session you are running at the point the … Read more