asp.net-identity

Entity Framework Seeding with Identity (Microsoft.Owin.Security) user

元气小坏坏 提交于 2019-12-05 10:32:46
I have a class that seed the database which add 2 users with roles and custom fields. The problem I have is that it save the data in [dbo].[AspNetUsers] instead of [dbo].[IdentityUsers]. Both tables are created. When seeded, the data go into AspNetUser. When I launch the web site, and register a new user, the data go into IdentityUser. Here is the Migration class : internal sealed class Configuration : DbMigrationsConfiguration<DatabaseContext> { public Configuration() { AutomaticMigrationsEnabled = true; } protected override void Seed(DatabaseContext context) { base.Seed(context); var

No MediaTypeFormatter is available to read an object of type 'Advertisement' in asp.net web api

戏子无情 提交于 2019-12-05 10:20:05
问题 I have a class that name is Advertisement: public class Advertisement { public string Title { get; set; } public string Desc { get; set; } } and in my controller: public class OrderController : ApiController { public UserManager<IdentityUser> UserManager { get; private set; } // Post api/Order/Test [Route("Test")] public IHttpActionResult Test(Advertisement advertisement) { var currentUser = User.Identity.GetUserId(); Task<IdentityUser> user = UserManager.FindByIdAsync(currentUser); return Ok

Claims without roles?

一笑奈何 提交于 2019-12-05 10:00:42
I'm trying to understand ASP.NET Identity authentication and authorization mechanics. I understood what's a claim & what's a role. In almost every related blog post, or question on here it's advised to use claims and avoid roles. I'm confused at this point. How can I use claims without roles? (I normally assign roles to users after they are registered. ) Any help is appreciated. Thank you Roles are claims too, claims are just more general. In almost every related blog post, or question on here it's advised to use claims and avoid roles. I can only speculate, as you don't show exact links, that

What is the default TokenLifespan of GeneratePasswordResetTokenAsync and GenerateUserTokenAsync

落爺英雄遲暮 提交于 2019-12-05 09:28:19
问题 I have looked everywhere and cannot seem to find out for sure what the default for each of these is. I also need to know if there is a way to set different Lifespans for each. Thanks, 回答1: The default is apparently 24 hours for any of the tokens. You can set it to a different value, but the same value will apply to all the tokens equally ( GenerateEmailConfirmationTokenAsync , GeneratePasswordResetTokenAsync and GenerateUserTokenAsync ). Setting a new value is done by specifying, for example,

How to generate Asp.net User identity when testing WebApi controllers

只谈情不闲聊 提交于 2019-12-05 09:07:22
I am using Web API 2. In web api controller I have used GetUserId method to generate user id using Asp.net Identity. I have to write MS unit test for that controller. How can I access user id from test project? I have attached sample code below. Web API Controller public IHttpActionResult SavePlayerLoc(IEnumerable<int> playerLocations) { int userId = RequestContext.Principal.Identity.GetUserId<int>(); bool isSavePlayerLocSaved = sample.SavePlayerLoc(userId, playerLocations); return Ok(isSavePlayerLocSaved ); } Web API Controller Test class [TestMethod()] public void SavePlayerLocTests() { var

The type ApplicationUser cannot be used as type parameter 'TUser' in the generic type or method 'IdentityDbContext<TUser>'

空扰寡人 提交于 2019-12-05 08:41:19
Trying to implement Identity in ASP.NET Core 2.0. Having many problems getting my head around this. Startup.cs public class Startup { public Startup(IConfiguration configuration) { Configuration = configuration; } public IConfiguration Configuration { get; } // This method gets called by the runtime. Use this method to add services to the container. public void ConfigureServices(IServiceCollection services) { services.AddDbContext<ApplicationDbContext>(options => options.UseSqlServer(Configuration.GetConnectionString("Ctrack6_Custom")) ); services.AddIdentity<ApplicationUser, ApplicationRole>(

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

非 Y 不嫁゛ 提交于 2019-12-05 07:42:25
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 EditUserMapItemAjax([FromBody]UserMapItemViewModel userMapItemViewModel) { var user = await

ASP.NET Identity doesn't update Identity information on same request

♀尐吖头ヾ 提交于 2019-12-05 07:16:04
I am working on a single page application using AngularJS and ASP.NET Identity 2. I log the user in and the cookie is set; however, when I check the Identity of the user on the same request, it shows it as blank and IsAuthenticated is false. However, these are populated on subsequent requests. I was hoping to send back to the UI whether or not the user was logged in on the same request. Is this possible? Code as requested (AngularJS makes AJAX post into WebAPI controller Login method) [HttpPost] [AllowAnonymous] [Route("Login")] public async Task<IHttpActionResult> Login(LoginModel loginModel)

ASP.NET Core 1.1 getting all users and their roles

拜拜、爱过 提交于 2019-12-05 06:47:27
I am new to .NET trying to get a list of all the registered user along with their role names and send them to a view using a viewModel. Here's the ViewModel: public class ApplicationUserListViewModel { [Display(Name = "User Email Address")] public string UserEmail { get; set; } public List<IdentityUserRole<string>> Roles { get; set; } } I tried this for getting all users along with their roles and make a ViewModel for each user and put all the view models in a list to pass to the View: var users = _userManager.Users.ToList(); var userList = users.Select(u => new ApplicationUserListViewModel {

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

扶醉桌前 提交于 2019-12-05 06:29:11
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 from here. :) There's no custom password hashing in the .NET Core app, and I'm struggling to find any