asp.net-identity

Inherit from IdentityUser I get an error on UserManager<User>

别等时光非礼了梦想. 提交于 2019-12-07 04:49:59
问题 I'm developing a Web Api 2.2 application with .NET Framework 4.5.1 and Asp.Net Identity 2.1.0. I'm not sure what I'm doing, but I want to merge my database with ASP.NET Identity database and I have done this: My own dbContext . public class EFDbContext : IdentityDbContext, IUnitOfWork My own User class. public class User : IdentityUser<long, IdentityUserLogin<long>, IdentityUserRole<long>, IdentityUserClaim<long> > But when I do this: UserManager<User> _userManager; I get this error: The type

ASP.net Identity 2.1 Get all users with roles

℡╲_俬逩灬. 提交于 2019-12-07 04:44:57
问题 How can I get a list of users including the role name per user? My app has the default tables of an MVC Project. I'm able to retrieve all users using Identity 2.1 like this: Model public class GetVendorViewModel { public IList<ApplicationUser> Vendors { get; set; } } Controller public ActionResult Index() { var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new ApplicationDbContext())); var roleStore = new RoleStore<IdentityRole>(ac); var roleManager = new

Add column to AspNetUsers table

大憨熊 提交于 2019-12-07 04:29:22
问题 Workstation setup: Windows 8.1 Pro Visual Studio Pro 2013 v 12.0.40629.00 Update 5 .Net v 4.6.01055 Background: I created my project using Individual Account Authentication and then following a guide I found on Youtube I created an EDMX Data Model from an existing database. I did this to create authentication for my website. I then modified the Default Connection in the web.config file to point to my existing database. When I registered the first user account after modifying the Default

How to resolve object disposed exception ASP.NET Core with Entity Framework and Identity

℡╲_俬逩灬. 提交于 2019-12-07 03:53:52
问题 I am trying to write a controller that receives a request from an AJAX call and performs some calls to the database via the DBContext. However, when I place the command var user = await GetCurrentUserAsynch(); in front of any calls to the DBContext, as shown below, I get an ObjectDisposedException (Cannot access a disposed object). It appears to be the UserManager and the DBContext not playing nicely together, however I can't find much information on the matter. [HttpPost] public async void

How to separate large cookies in Asp.Net Identity into a smaller ones to allow MANY claims?

ぐ巨炮叔叔 提交于 2019-12-07 03:06:00
问题 I'm working on a prototype of a claims-based authorisation for our MVC application. We use Asp.Net Identity for authentication. We would like to have a claim for every controller action and then give/take away users' claims so we have a very fine control over who can go where. Our application already has 800+ actions and keeps growing. I have made a little test app to see how this number of claims can be handled. And run into a problem: cookies are limited to 4092 bytes. And having a large

Password (hash) doesn't match when re-using existing Microsoft Identity user tables

谁都会走 提交于 2019-12-07 02:48:55
问题 We have an existing SQL database with Microsoft Identity tables, originally generated by a ASP.NET Core app. We also have an ASP.NET 4 app, which also uses Microsoft Identity. We'd like the ASP.NET 4 app to be able to validate logins using the same database as the original .NET Core app. However, when we try to validate passwords, they don't match. I'm just guessing that the password hashes generated by the .NET Core app cannot be validated by the ASP.NET 4 app, but I'm not sure where to go

ASP.NET-Identity limit UserName length

南楼画角 提交于 2019-12-07 01:06:05
问题 How can I limit the UserName field in the table AspNetUsers ? Neither this: public class ApplicationUser : IdentityUser { [Required, MaxLength(15)] public string UserName { get; set; } } or this: modelBuilder.Entity<ApplicationUser>().Property(x => x.UserName).HasMaxLength(15); works. I need this because setting an Index on an nvarchar(max) gives me this error msg: Column 'UserName' in table 'dbo.AspNetUsers' is of a type that is invalid for use as a key column in an index. To be verbose, I

Why does Logout in ASP.NET Identity use POST instead of GET? [duplicate]

会有一股神秘感。 提交于 2019-12-07 00:37:55
问题 This question already has answers here : Logout: GET or POST? (9 answers) Closed 5 years ago . The sample Identity project uses this to log out: @if (Request.IsAuthenticated) { using (Html.BeginForm("LogOff", "Account", FormMethod.Post, new { id = "logoutForm", @class = "navbar-right" })) { @Html.AntiForgeryToken() <ul class="nav navbar-nav navbar-right"> <li>@Html.ActionLink("Hello " + User.Identity.GetUserName() + "!", "Index", "Manage", routeValues: null, htmlAttributes: new { title =

How to securely send a message to a specific user

主宰稳场 提交于 2019-12-07 00:28:35
问题 I am using ASP.NET MVC 5 and SignalR. I want to send a message to a specific user. I have followed the method which is explained in this tutorial (also suggested by this answer). I have overridden IUserIdProvider , to use UserId as connectionId . public class SignalRUserIdProvider : IUserIdProvider { public string GetUserId(IRequest request) { // use: UserId as connectionId return Convert.ToString(request.User.Identity.GetUserId<int>()); } } And I have made the change to my app Startup to use

User Role/Authorization doesn't work in ASP.NET Identity

不羁的心 提交于 2019-12-07 00:28:28
have this (model builder) code on our DbContext.cs base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId); modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id); modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId }); modelBuilder.Entity<ApplicationUser>().ToTable("ApplicationUser"); Everything works fine except for Authorization/User Roles . After checking all tables I noticed that IdentityUserRoles table creates 4 columns: RoleId, UserId, IdentityRole_Id and ApplicationUser_Id. I found out that, IdentityRole