asp.net-identity

Why is ASP.NET Identity 2.0 using a GUID/string as user id?

笑着哭i 提交于 2019-12-03 17:57:37
问题 As the title says, I wonder, why ASP.NET Identity 2.0 uses a string with a GUID as primary clustered key for the user table. Does this have any advantages to an integer id? I see only the problem, that a GUID isn't the best choice for a clustered index. Am I missing anything or is a integer still the better choice? 回答1: Regarding the use of guid, there is a point of view that promotes using ids without "meaning" in order to completely separate the identifier from the data surrounding it; this

Issues Configuring StructureMap.MVC5 to work with Identity

空扰寡人 提交于 2019-12-03 17:06:09
I am currently trying to reconfigure StructureMap in our application after upgrading from an old version (2.6) that was never correctly implemented in the first place. I am new to using DI Containers to begin with, and am finding documentation for newer StructureMap versions hard to find. I uninstalled the old 2.6 version of StructureMap and installed StructureMap.MVC5 (since I am using MVC5). What I am having issues with is the AccountController. I have StructureMap set up to use the parameterless constructor, but when my application tries to create the UserManager, I get an

Identity Framework test if confirm email token is expired

房东的猫 提交于 2019-12-03 16:34:47
问题 Is it possible to test whether a confirm email token is expired using Identity Framework's UserManager ? No matter what the error is, from the following: var result = await UserManager.ConfirmEmailAsync(userId, code); I get a generic "Invalid Token" error. 回答1: I found a way to parse the token for the date issued, which you can then check to see if is within the allowed timespan (default of 24hours if not specified). Identity.cs ApplicationUserManager public IDataProtector Protector { get;

How to add a Foreign key in Customer table (CreatedBy column) for AspNetUser table (Id column) in ASP.NET MVC 5 Identity 2.0 using Code First

让人想犯罪 __ 提交于 2019-12-03 16:24:09
I have created Empty MVC (ASP.NET Web Application) project using Visual Studio 2013 Update 2 RC & then added AspNet Identity Samples using: PM>Install-Package Microsoft.AspNet.Identity.Samples -Pre I have enabled and added migrations & then updated database, which created default tables. I want to create Customer table which contains 2 columns as Foreign Keys to: Groups table (GroupId column) AspNetUsers table (Id column) So I have created 2 classes Customer & Group and added Foreign Keys using Data-annotations as shown below: namespace IdentitySample.Models { // You can add profile data for

How to handle cookie expiration in asp.net core

三世轮回 提交于 2019-12-03 16:17:59
I would like to know how to properly handle the fact that the cookie expired? Is it possible to execute a custom action ? What I would like to achieve is that when the cookie is expired is to take few informations out of the current cookie at redirect to a action parametrise by this information. Is it possible ? Looks like you need your own handler for OnValidatePrincipal event when setuping cokies auth middleware: OnValidatePrincipal event can be used to intercept and override validation of the cookie identity app.UseCookieAuthentication(options => { options.Events = new

ASP.NET MVC 5 Identity 2.0, Windows Auth, User model with role attribute

折月煮酒 提交于 2019-12-03 15:43:16
I'm trying to create an MVC5 application that uses Windows Authentication but uses roles pulled from a User model. I've searched high and low for an example, but the only ones I can find are based on the old ASP.NET identity framework. Anyone care to point me in the right direction?! Thanks! So I've figured out one approach to solving this problem. I created a custom Authorization Attribute that checks the User model for a role. using System.Linq; using System.Web; using System.Web.Mvc; using App.Models; using System.Security.Claims; namespace App.Extensions.Attributes { public class

Asp.net Core Identity Use AspNetUserClaims or AspNetRoleClaims?

落花浮王杯 提交于 2019-12-03 15:41:30
问题 I am still confused about all this Identity stuff. First I am still confused the difference between Roles, Policies/Claims. From what I read roles is the old way of doing stuff and was kept for backward compatibility, so does that mean AspNetRoleClaims is part of this backward compatibility? I think I understand Claims and Policies when thinking of them individual, like policy is basically a set of rules that must pass and gives the ability to change rules without having to go through out all

Extending IdentityRole and IdentityUser

廉价感情. 提交于 2019-12-03 15:27:21
I am using ASPNet Identity to implement security in my web application. There is a requirements where in, I need to extend the IdentityRole and IdentityUser. Here is my code to extend the IdentityUser. public class ApplicationUser : IdentityUser { public virtual User User { get; set; } } public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() : base("name=CoreContext") { } protected override void OnModelCreating(DbModelBuilder modelBuilder) { base.OnModelCreating(modelBuilder); modelBuilder.Entity<IdentityUser>() .ToTable("AspNetUsers");

Proper way to get current User ID in Entity Framework Core

懵懂的女人 提交于 2019-12-03 15:15:42
问题 There are a bunch of different answers floating around here for the different RC's of ASP.NET Core on how to get the ID of the currently logged in user. I wanted to ask the definite question here. Please note that project.json now has "Microsoft.AspNetCore.Identity.EntityFrameworkCore": "1.0.0" With RC1, you could do something like this: using Microsoft.AspNet.Identity; using System.Security.Claims; User.GetUserId(); But with the newly released version 1 of EF Core, Microsoft.AspNet.Identity

Always receiving 'invalid_client' error when POSTing to /Token endpoint with ASP Identity 2

扶醉桌前 提交于 2019-12-03 15:12:09
问题 About a month ago I had a project working perfectly with ASP Identity OAuth. I'd send a POST request to the /Token endpoint with grant_type, username, and password, and all was dandy. I recently started a new project based off of Visual Studio 2013 RC2's SPA template. It's a bit different than the old template. Authentication is set up to pretty basic defaults, OAuthOptions = new OAuthAuthorizationServerOptions { TokenEndpointPath = new PathString("/Token"), //AuthorizeEndpointPath = new