asp.net-identity

How to show MVC logged in username with AngularJs

不问归期 提交于 2019-12-07 14:42:25
问题 I am using MVC 5 / WebApi 2 and AngularJs. I want to display the Logged in username in my view. I know how to display that information using razor but how can I do it with Angular? So basically I need to do this with Angular. <span >Logged In As: @Html.ActionLink(User.Identity.GetUserName(), "Manage", "Account", routeValues: null, htmlAttributes: new { title = "Manage", @style = "color:white;float:right" })</span> apiUserController public class apiUserController : ApiController { // GET api/

Setup Simple Injector with ASP.NET Identity 2.2.1

只愿长相守 提交于 2019-12-07 12:55:10
问题 So I've been trying to setup ASP.NET Identity 2.2.1 and I keep hitting roadblocks. For being something that is supposed to be auto-generated by the framework it sure seems complicated to configure. I think I'm almost there but I'm still having issues setting up IoC with Simple Injector. I've been reading through other StackOverflow questions and blogs about these issues. Most of them seem out of date because they deal with ASP.NET Identity 1.0. There's even been enough changes from 2.0 to 2.2

Transactions with ASP.NET Identity UserManager

瘦欲@ 提交于 2019-12-07 11:05:21
问题 I'm trying to update a user. AppUserManager appUserManager = HttpContext.GetOwinContext().GetUserManager<AppUserManager>(); AppUser member = await appUserManager.FindByIdAsync(User.Identity.GetUserId()); member.HasScheduledChanges = true; IdentityResult identityResult = appUserManager.Update(member); If a subsequent call to a Web API fails, I need to roll back any changes to the user. I know about transactions, like this: using (var context = HttpContext.GetOwinContext().Get<EFDbContext>()) {

Get all users for a certain claim?

放肆的年华 提交于 2019-12-07 10:10:43
问题 For ASP.NET Identity 2.0: Does anybody know how to get "all users that have a given claim assigned"? Let's say I have a claim with type="ArticleId" and value="1". How can I get all users that have this claim? I really couldn't figure it out .. so, thanks for any help!! 回答1: Check this one. var userContext = new ApplicationDbContext(); var users = userContext.Users.ToList(); Or var users = UserManager.Users.ToList(); var userfilter = users.Where(u => u.Claims.Any(t => t.ClaimType == "ArticleId

Asp.Net Identity - case insensitive email and usernames

落爺英雄遲暮 提交于 2019-12-07 08:20:40
问题 Is there a way to get Asp.Net Identity to be case insensitive with email addresses and usernames? At the moment if I call "FindByEmailAsync(email)" it will only work if the email address is being stored exactly as it's is typed (case sensitive) 回答1: You can change how the user is registered so that the username is set to lowercase and when logging in as well. For registering the user, in the AccountController [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task

ASP.Net MVC: How to read my custom claims value

假装没事ソ 提交于 2019-12-07 07:30:54
问题 See the below code. I got to know that this way we can add our custom data to claims but now question is how to read back those value. Say I want to read back value for claims Email and Email2 please tell me what code I need to write to read back value for claims Email and Email2 . UserManager<applicationuser> userManager = new UserManager<applicationuser>(new UserStore<applicationuser>(new SecurityContext())); ClaimsIdentity identity = userManager.CreateIdentity(user,

Roles vs Claims Authorization Asp.net web api-2 with WIF and OWIN Middleware

此生再无相见时 提交于 2019-12-07 06:30:17
问题 I am trying to secure asp.net web-api 2.0 with Windows Identity Foundation 2. The choice I have to make is between role based authorization and claims based authorization. As a practice, I added a users in DbInitializer and assigned him two roles (Admin and Manager). When I log in with that user, I see that ClaimsPrincipal in debug mode, it already has those roles (Admin and Manager) associated as claims. So here are the questions: If roles are also treated as claims, what is the difference b

Claims without roles?

别来无恙 提交于 2019-12-07 06:13:58
问题 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 回答1: Roles are claims too, claims are just more general. In almost every related blog post, or question

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

只愿长相守 提交于 2019-12-07 05:59:12
问题 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

ASP.NET Identity external authentication provider custom icon

岁酱吖の 提交于 2019-12-07 05:19:35
问题 With SimpleMembership you can add an icon to the external authentication provider buttons like this: SimpleMembership: Dictionary<string, object> FacebooksocialData = new Dictionary<string, object>(); FacebooksocialData.Add("Icon", "/content/images/gui/loginFacebook.png"); OAuthWebSecurity.RegisterFacebookClient( appId: "x", appSecret: "x", displayName: "Facebook", extraData: FacebooksocialData); And then display them like this in your view: @foreach (AuthenticationClientData p in Model) {