asp.net-identity

ASP.NET Core 2.1 Identity: Role-based authorization -> Access Denied

懵懂的女人 提交于 2019-12-17 19:51:46
问题 I'm using ASP.NET Core 2.1 with the new Identity framwork from .NET. The regular Authorization attribute works as long as no role specific role is requested. Do I need some extending / customized policies to use roles? Below is a minimized sample of my code: Startup.cs public void ConfigureServices(IServiceCollection services) { services.Configure<CookiePolicyOptions>(options => { // This lambda determines whether user consent for non-essential cookies is needed for a given request. options

SmtpClient.SendMailAsync causes deadlock when throwing a specific exception

China☆狼群 提交于 2019-12-17 19:12:23
问题 I'm trying to setup email confirmation for an ASP.NET MVC5 website, based on the example AccountController from the VS2013 project template. I've implemented the IIdentityMessageService using SmtpClient , trying to keep it as simple as possible: public class EmailService : IIdentityMessageService { public async Task SendAsync(IdentityMessage message) { using(var client = new SmtpClient()) { var mailMessage = new MailMessage("some.guy@company.com", message.Destination, message.Subject, message

How can customize Asp.net Identity 2 username already taken validation message?

久未见 提交于 2019-12-17 18:50:15
问题 How can i customize Asp.net Identity 2 username already taken validation message(Name XYZ is already taken.)? Thanks 回答1: Well, I didn't find any simple solution to this issue. And by simple i mean modifying some message in a attribute/model/controller. One possible solution could be: After executing var result = await UserManager.CreateAsync(user, model.Password); In case that result is not successful you can check it's Errors property for the "Name XYZ is already taken." pattern and replace

Updating asp.net MVC from 5.0.0-beta2 to 5.0.0-rc1

别来无恙 提交于 2019-12-17 18:44:19
问题 Last night, I decided to try and implement SignalR to my application, and because I use MVC 5, I had to use the 2.0 beta of SignalR. And oh boy, what a timing. Last night, Microsoft also decided to roll out rc1 of all their mvc 5 related packages, and updating broke a few things - mostly in the account controller that is in the template for beta2. public AccountController() { IdentityStore = new IdentityStoreManager(); AuthenticationManager = new IdentityAuthenticationManager(IdentityStore);

Dotnet core 2.0 authentication multiple schemas identity cookies and jwt

旧城冷巷雨未停 提交于 2019-12-17 17:44:07
问题 In dotnet core 1.1 asp, I was able to configure and use identity middleware followed by jwt middleware by doing the following: app.UseIdentity(); app.UseJwtBearerAuthentication(new JwtBearerOptions() {}); This has now changed in that we implement the middleware with: app.UseAuthentication(); Configuration of the settings is done via the ConfigureServices section of Startup.cs. There are some references to the use of authorization schema's in the migration documentation: https://docs.microsoft

Add role in ASP.NET Identity

别来无恙 提交于 2019-12-17 17:36:13
问题 How can I add a Role in the new ASP.NET Identity system (1.0)? There is a UserStore class but no RoleStore class. I can't find any documentation on this issue. 回答1: RoleManager = new RoleManager<IdentityRole>( new RoleStore<IdentityRole>(new MyDbContext())); var roleresult = RoleManager.Create(new IdentityRole(roleName)); 回答2: Starting with the .NET Framework 4.5, Windows Identity Foundation (WIF) has been fully integrated into the .NET Framework. I would advice to examine the possibility, in

How to Seed Users and Roles with Code First Migration using Identity ASP.NET Core

ぃ、小莉子 提交于 2019-12-17 17:29:13
问题 I have created a new clean asp.net 5 project (rc1-final). Using Identity Authentication I just have the ApplicationDbContext.cs with the following code: public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { protected override void OnModelCreating(ModelBuilder builder) { // On event model creating base.OnModelCreating(builder); } } Please note ApplicationDbContext use IdentityDbContext and not DbContext. There is any IdentityConfig.cs. Where i need to put the classic

Asp.net identity entity framework database first approach with own table defintion

梦想的初衷 提交于 2019-12-17 16:54:31
问题 I have below four tables Role table User table UserRole table UserType table default Asp.net identity having below tables like Asp.netusers,Asp.netRoles,Asp.netuserlogins,Asp.netuserclaims,Asp.netuserroles My table doesn't match the same column name and some columns not available in my tables. can i use my own tables to utilize the feature of asp.net identity or else i need to follow the same columns used in Asp.netusers table to my User table. Is that all columns necessary to add in my table

Invalid object name 'dbo.AspNetUsers' in Asp.NET MVC 5 Entity Framework

爱⌒轻易说出口 提交于 2019-12-17 16:29:13
问题 If you have an existing database, and if you want to include ASP.NET Identity tables to it, you can face this error. Also in the beginning, you may not know how to integrate [AspNetRoles], [AspNetUserClaims], [AspNetUsers], [AspNetUserLogins] tables into your existing database. Although there are a lot of resources about this topic, this answer tries to be short and to the point. You may want to use the Database-First approach in Entity Framework together with the ASP.NET Identity feature of

Why does this violate the type constraint?

给你一囗甜甜゛ 提交于 2019-12-17 16:18:29
问题 I'm trying to customise ASP.NET Identity 3 so that it uses integer keys: public class ApplicationUserLogin : IdentityUserLogin<int> { } public class ApplicationUserRole : IdentityUserRole<int> { } public class ApplicationUserClaim : IdentityUserClaim<int> { } public sealed class ApplicationRole : IdentityRole<int> { public ApplicationRole() { } public ApplicationRole(string name) { Name = name; } } public class ApplicationUserStore : UserStore<ApplicationUser, ApplicationRole,