Disable User in ASPNET identity 2.0

When you create a site with the Identity bits installed, your site will have a file called “IdentityModels.cs”. In this file is a class called ApplicationUser which inherits from IdentityUser. // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit https://devblogs.microsoft.com/aspnet/customizing-profile-information-in-asp-net-identity-in-vs-2013-templates/ to learn more. public class … Read more

“Context cannot be used while the model is being created” exception with ASP.NET Identity

The problem was that we were NOT using the factory pattern that MS recommends. You can use Factory implementation to get an instance of UserManager from the OWIN context. … This is a recommended way of getting an instance of UserManager per request for the application. As a result, “the same context instance is accessed … Read more

Get UserID of logged-in user in Asp.Net MVC 5

The answer is right there in your code. What does this return? var userID = User.Identity.GetUserId(); If you are using ASP.NET Identity, then after logging in (and redirecting to another page), the IPrincipal.IIdentity should be a ClaimsIdentity. You can try this: var claimsIdentity = User.Identity as ClaimsIdentity; if (claimsIdentity != null) { // the principal … Read more

Register IAuthenticationManager with Simple Injector

As TrailMax already mentioned, the exception you got probably got raised during the call to container.Verify(). At application start-up time there is no HttpContext, hence the exception. Although the removal of the call to container.Verify() will ‘solve’ the problem, I would advise against doing this and I will suggest a better solution below. NightOwl888 references … Read more

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

Why is Asp.Net Identity IdentityDbContext a Black-Box?

The ApplicationDbContext‘s Users and Roles properties are mapped to the AspNetUsers and AspNetRoles tables, and the rest of the entities (Claims, Logins, UserRoles) are mapped automatically via navigation properties. As far as I know, the prefixing of table names with “AspNet” are the only custom mappings in ApplicationDbContext, everything else is just Entity Framework Code … 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 (OWIN) Identity: How to get UserID from a Web API controller?

You should be able to get user id on both MVC controller and web api controller by same extension method in identity 1.0 RTW package. Here is the extensions from identity package: namespace Microsoft.AspNet.Identity { public static class IdentityExtensions { public static string FindFirstValue(this ClaimsIdentity identity, string claimType); public static string GetUserId(this IIdentity identity); public … 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

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