asp.net-identity-3

Why this violates the constraint of type parameter 'TUser'?

南笙酒味 提交于 2019-12-12 08:47:52
问题 I am trying to customize asp.net identity entities with the following ones: public class User : IdentityUser<string, UserClaim, UserRole, UserLogin> public class UserClaim : IdentityUserClaim<string> public class UserLogin : IdentityUserLogin<string> public class UserRole : IdentityUserRole<string> public class UserToken : IdentityUserToken<string> public class Role : IdentityRole<string, UserRole, RoleClaim> public class RoleClaim : IdentityRoleClaim<string> I have then created a DbContext

Update Claims values in ASP.NET One Core

早过忘川 提交于 2019-12-12 07:50:44
问题 I have a Web Application in MVC 6 (Asp.Net One Core), and I'm using Claims based authentication. In the Login method I set the Claims: var claims = new Claim[] { new Claim("Name", content.Name), new Claim("Email", content.Email), new Claim("RoleId", content.RoleId.ToString()), }; var ci = new ClaimsIdentity(claims, "password"); await HttpContext.Authentication.SignInAsync("Cookies", new ClaimsPrincipal(ci)); Now, if the user for example changes the email in the user profile, how can I change

.Net Identity 3 on existing solution

南笙酒味 提交于 2019-12-11 17:43:49
问题 I believe that .NET Identity 3 cannot run on an existing (v4.5) ASP.NET solution, but requires .NET Core. I cannot update to .NET Core. Is there a workaround for this? If not then how are people supposed to migrate from ASP.NET Membership to ASP.Net Identity? 回答1: First of all, I need to note that ASP.NET Core (which works with Identity 3) does not require .NET Core. It can be used either over .NET Core or .NET Framework 4.6.1 (or higher). I guess you use the default approach in both cases

Using a Custom SignInManager

▼魔方 西西 提交于 2019-12-11 15:00:46
问题 I setup identity as follows: services.AddIdentity<IdentityUser, IdentityRole>( c => { c.Password.RequireDigit = false; c.Password.RequiredLength = 8; c.Password.RequireLowercase = false; c.Password.RequireNonLetterOrDigit = false; c.Password.RequireUppercase = false; }) .AddUserManager<CustomUserManager>() .AddUserValidator<CustomUserValidator>() .AddCustomStores<PrimaryContext>() .AddDefaultTokenProviders(); I'd like to use a custom sign-in manager, but there is no AddSignInManager method. I

Using a Custom SignInManager

五迷三道 提交于 2019-12-11 13:54:05
问题 I setup identity as follows: services.AddIdentity<IdentityUser, IdentityRole>( c => { c.Password.RequireDigit = false; c.Password.RequiredLength = 8; c.Password.RequireLowercase = false; c.Password.RequireNonLetterOrDigit = false; c.Password.RequireUppercase = false; }) .AddUserManager<CustomUserManager>() .AddUserValidator<CustomUserValidator>() .AddCustomStores<PrimaryContext>() .AddDefaultTokenProviders(); I'd like to use a custom sign-in manager, but there is no AddSignInManager method. I

ASP.NET 5 Identity 3.0 scalability with CookieAuthentication

☆樱花仙子☆ 提交于 2019-12-11 11:56:12
问题 I'm using ASP.NET 5 with MVC6. I am working with Identity 3.0, but I need to know how to make it works with many webservers. Is possible to store the session in other place? Database? In MVC5 you did that in the web.config, but I don't found information about it in MVC6. This is my code in Startup.cs app.UseCookieAuthentication(options => { options.AutomaticAuthenticate = true; options.LoginPath = new PathString("/Account/Login"); options.AutomaticChallenge = true; }); Thanks!! 回答1: By

DbContext cannot find database

一曲冷凌霜 提交于 2019-12-11 10:42:05
问题 The connection string for our app is set in appsettings.json "Data": { "DefaultConnection": { "ConnectionString": "Server=(localdb)\\mssqllocaldb;Database=Customers;Trusted_Connection=True;MultipleActiveResultSets=true", In ConfigureServices we have services.AddEntityFramework() .AddSqlServer() .AddDbContext<CustomersContext>(options => options.UseSqlServer(Configuration["Data:DefaultConnection:ConnectionString"])); This seems to work in cases like this var membershipUser = await _userManager

Entity type 'type' is in shadow-state. A valid model requires all entity types to have corresponding CLR type

浪尽此生 提交于 2019-12-10 18:09:52
问题 I am working from an example to set up IdentityServer4 using Asp.net Core and EF core. During the process I wanted to separate my data contracts and data access from the core project. To do that I created two related projects, one containing the DbContext and one containing the contracts. Eventually I'd like to make things more complicated, but to start I am simply trying to add a related object to the IdentityUser, which is defaulted to ApplicationUser and stored as ApsnetUsers in default

Checking for one of multiple policies with Authorize attribute in ASP.NET Core Identity

﹥>﹥吖頭↗ 提交于 2019-12-10 15:55:32
问题 I have setup a standard authentication system up in an ASP.NET Core application. Users, Roles, RoleClaims(acting as permissions) In Startup.cs I create a policy for each Role and each Permission. Assuming this would give me full flexibility in my Views to be able to say I want this button to show if user is part of a role that has claim DeleteCustomer or if User belongs to role Superuser. How can I do an OR condition using the Authorize attribute. For example all throughout my site I want

UserValidator in Microsoft.AspNet.Identity vnext

天涯浪子 提交于 2019-12-10 15:50:00
问题 I have a problem where I cant use email addresses as usernames when using microsoft.aspnet.identity (Individual user accounts selected when creating new project - default mvc project template for asp.net 5). I have read in many places that this is the solution: UserManager.UserValidator = new UserValidator<ApplicationUser>(UserManager) { AllowOnlyAlphanumericUserNames = false }; But in the new version of asp.net identity, UserManager doesnt seem to have a property called UserValidator. The