aspnet-identity-2-extending-users-and-roles's People
Forkers
kennylisc abstract4713 jamesmaxwell charreal jtnichols kerryjiang rodrigoratan wakecaine salvie folake olegil joshyates1980 eqdesign syatin003 huoxudong125 sql2005programmer was2792 likhi1 berlstone yonidev kbajpai wguanwei ocepchuang yuanchunsong miladramsys sutav zarinbal rpatlan gojeda04 tony-yi-zhou aspnetsample grim-fendango modulexcite pixel-stroke vegasoftti deddyagustinus codebuger88 talalalshehri bruceliu2008 zhangrl jorgecabezudo st-elmos tesla9527 omiguelperez sonuame polalucash jackjet dillishrestha m13810859213 lufinima senthilmsv dodousamba mahammadmoine ademzeina dinhducit wangzhefeng2000 mike-geiger rafysanchez karim-devdotnet ayhamatiyah sayitfast devx-realtobiz manozbiswas zzekikaya jazoora simon9k manhnguyenv jiutianshidi6 markchipman msec1297 amitdumka jerryzfc innocentalfredo simonwaechter1aspnet-identity-2-extending-users-and-roles's Issues
how to change the identity table name and then customize user and role
I follow your AspNet-Identity-2-Extending-Users-And-Roles tutorial and it working fine .But i wanted to change my Identity table name.I wrote the code as below
public class ApplicationDbContext : IdentityDbContext
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
protected override void OnModelCreating(System.Data.Entity.DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<IdentityUser>().ToTable("user");
modelBuilder.Entity<ApplicationUser>().ToTable("user");
modelBuilder.Entity<IdentityRole>().ToTable("role");
modelBuilder.Entity<IdentityUserRole>().ToTable("userrole");
modelBuilder.Entity<IdentityUserClaim>().ToTable("userclaim");
modelBuilder.Entity<IdentityUserLogin>().ToTable("userlogin");
}
}
it changes identity table name.but create a problem in userroles table an extra column added [IdentityUser_Id] NVARCHAR (128) NULL, and when i add user and user role no data added in this field .and [authorize(Role="Admin,User")] always return log in page .how can it solved ?please give suggession? the userroles table script is below:
CREATE TABLE [dbo].[userrole]([UserId] NVARCHAR %28128%29 NOT NULL,
[RoleId] NVARCHAR %28128%29 NOT NULL,
[IdentityUser_Id] NVARCHAR %28128%29 NULL,
CONSTRAINT [PK_dbo.userrole] PRIMARY KEY CLUSTERED %28[UserId] ASC, [RoleId] ASC%29,
CONSTRAINT [FK_dbo.userrole_dbo.mcms_role_RoleId] FOREIGN KEY %28[RoleId]%29 REFERENCES [dbo].[role] %28[Role_ID]%29 ON DELETE CASCADE,
CONSTRAINT [FK_dbo.mcms_userrole_dbo.mcms_user_IdentityUser_Id] FOREIGN KEY %28[IdentityUser_Id]%29 REFERENCES [dbo].[user] %28[User_ID]%29);
Cannot access the database
What are the user and password of the provided default database?
Updating online users
Hi
I have one simple question, how to update a users roles when he is aldready login...
I want to update a users role on the fly:
Something like this:
... check user
var roles = new List();
roles.Add("NormalUser");
roles.Add("CreateOffer");
var currentUser = User.Identity.GetUserId();
await UserManager.AddToRolesAsync(currentUser, roles: roles.ToArray());
The problem is that I can only regonize with the new role after he has sign out and in again, how can I update the current user?
cannot create an instance using UserStore
I've changed my code according to your resources.
following section Inside the IdentityConfig.cs
// Configure the application user manager used in this application. UserManager is defined in ASP.NET Identity and is used by the application.
public class ApplicationUserManager : UserManager<ApplicationUser>
{
public ApplicationUserManager(IUserStore<ApplicationUser> store)
: base(store)
{
}
public static ApplicationUserManager Create(IdentityFactoryOptions<ApplicationUserManager> options, IOwinContext context)
{
var manager = new ApplicationUserManager(new UserStore<ApplicationUser>(context.Get<ApplicationDbContext>()));
// Configure validation logic for usernames
manager.UserValidator = new UserValidator<ApplicationUser>(manager)
{
AllowOnlyAlphanumericUserNames = false,
RequireUniqueEmail = true
};
// Configure validation logic for passwords
manager.PasswordValidator = new PasswordValidator
{
RequiredLength = 6,
RequireNonLetterOrDigit = true,
RequireDigit = true,
RequireLowercase = true,
RequireUppercase = true,
};
// Configure user lockout defaults
manager.UserLockoutEnabledByDefault = true;
manager.DefaultAccountLockoutTimeSpan = TimeSpan.FromMinutes(5);
manager.MaxFailedAccessAttemptsBeforeLockout = 5;
// Register two factor authentication providers. This application uses Phone and Emails as a step of receiving a code for verifying the user
// You can write your own provider and plug it in here.
manager.RegisterTwoFactorProvider("Phone Code", new PhoneNumberTokenProvider<ApplicationUser>
{
MessageFormat = "Your security code is {0}"
});
manager.RegisterTwoFactorProvider("Email Code", new EmailTokenProvider<ApplicationUser>
{
Subject = "Security Code",
BodyFormat = "Your security code is {0}"
});
manager.EmailService = new EmailService();
manager.SmsService = new SmsService();
var dataProtectionProvider = options.DataProtectionProvider;
if (dataProtectionProvider != null)
{
manager.UserTokenProvider =
new DataProtectorTokenProvider<ApplicationUser>(dataProtectionProvider.Create("ASP.NET Identity"));
}
return manager;
}
}
then I changed IdentityModel.cs as follows
// You will not likely need to customize there, but it is necessary/easier to create our own
// project-specific implementations, so here they are:
public class ApplicationUserLogin : IdentityUserLogin<string> { }
public class ApplicationUserClaim : IdentityUserClaim<string> { }
public class ApplicationUserRole : IdentityUserRole<string> { }
//Must be expressed in terms of our custom Role and other types:
public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationUser()
{
this.Id = Guid.NewGuid().ToString();
// Add any custom User properties/code here
}
///******************************* I added custom properties here *************************************
public async Task<ClaimsIdentity>
GenerateUserIdentityAsync(ApplicationUserManager manager)
{
var userIdentity = await manager
.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie);
return userIdentity;
}
}
// Must be expressed in terms of our custom UserRole:
public class ApplicationRole : IdentityRole<string, ApplicationUserRole>
{
public ApplicationRole()
{
this.Id = Guid.NewGuid().ToString();
}
public ApplicationRole(string name)
: this()
{
this.Name = name;
}
// Add any custom Role properties/code here
}
// Must be expressed in terms of our custom types:
public class ApplicationDbContext
: IdentityDbContext<ApplicationUser, ApplicationRole,
string, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>
{
public ApplicationDbContext()
: base("DefaultConnection")
{
}
//static ApplicationDbContext()
//{
// Database.SetInitializer<ApplicationDbContext>(new ApplicationDbInitializer());
//}
public static ApplicationDbContext Create()
{
return new ApplicationDbContext();
}
// Add additional items here as needed
}
// Most likely won't need to customize these either, but they were needed because we implemented
// custom versions of all the other types:
public class ApplicationUserStore
: UserStore<ApplicationUser, ApplicationRole, string,
ApplicationUserLogin, ApplicationUserRole,
ApplicationUserClaim>, IUserStore<ApplicationUser, string>,
IDisposable
{
public ApplicationUserStore()
: this(new IdentityDbContext())
{
base.DisposeContext = true;
}
public ApplicationUserStore(DbContext context)
: base(context)
{
}
}
public class ApplicationRoleStore
: RoleStore<ApplicationRole, string, ApplicationUserRole>,
IQueryableRoleStore<ApplicationRole, string>,
IRoleStore<ApplicationRole, string>, IDisposable
{
public ApplicationRoleStore()
: base(new IdentityDbContext())
{
base.DisposeContext = true;
}
public ApplicationRoleStore(DbContext context)
: base(context)
{
}
}
then I cannot sign in properly with correct credentials
getting this error
"The view 'Index' or its master was not found or no view engine supports the searched locations. The following locations were searched:"
Error When Declaring roleManager
I currently had this for defining the roleManager:
var roleManager = new RoleManager<ApplicationRole>(new RoleStore<ApplicationRole>(context));
Your code says to use this:
var roleManager = HttpContext.Current.GetOwinContext().Get<ApplicationRoleManager>();
I'm getting an error for the ApplicationRoleManager saying this:
There is no argument given that corresponds to the required formal parameter 'key' of 'IOwinContect.Get(string)'
All of my other code is the same. Do you know what the issue could be? I have defined the ApplicationRoleManager exactly like your code.
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ๐๐๐
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google โค๏ธ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.