asp.net-identity

asp Identity 2.0 adding new roles and adding user to roles

ⅰ亾dé卋堺 提交于 2019-12-03 11:59:24
I'm having trouble understanding the new Identity stuff. I'm trying to figure out how to add new roles and add user's to those roles. I'm trying to create a role management page and a user management page for my application and need to be able to do those two things. Everytime i try to add a role to a user like this: System.Web.Security.Roles.AddUserToRole("Andy", "admin"); I get "The Role Manager feature has not been enabled." I don't have a custom role provider and i tried turning role manager to enabled but just got an error about not having a role provider. I figured Identity had all this

How to access User in a service context in web API?

僤鯓⒐⒋嵵緔 提交于 2019-12-03 11:55:11
If you are in a controller context, you can access the current authenticated User. Take an article such as Get the current user, within an ApiController action, without passing the userID as a parameter . However, if my controller calls a service (same assembly), but here I don't have the controller context. What is the best way to actually get the authenticated user? You can create an intermediate service to provide that functionality public interface IPrincipalProvider { IPrincipal User { get; } } public class WebApiPrincipalProvider : IPrincipalProvider { public IPrincipal User { get {

Getting a list of logged-in users in ASP.NET Identity

僤鯓⒐⒋嵵緔 提交于 2019-12-03 11:43:01
问题 I'm getting started with ASP.NET Identity, but I've been unable to find a way to fetch a list of the current logged in users. To get all users I can just user new ApplicationDbContext().Users where ApplicationDbContext comes with the ASP.NET Web Application template, and extends IdentityDbContext . But the IdentityUser class does not seem to have any way to query for the logged in status. Thank you for any pointers. 回答1: There is no built in support for this. One simple way you could

Talking to IdentityServer4 with an Angular SPA application for authentication/authorization receiving a token then talking to Web API

橙三吉。 提交于 2019-12-03 11:35:55
问题 I have an asp.net core Web API. I am currently making calls directly to it using an Angular 4 app. I now want to add authentication and authorization layer. I would like to do this by adding another project (strictly for auth) of type : ASP.NET Core MVC (w/ Individual User Accounts) to my solution and then adding IdentityServer4 to it. The plan is to use the existing Identity tables to store users, roles, etc. Once this is all setup I am a bit confused about how my Angular 4 SPA app or any

How to add Azure AD Authentication to Existing ASP.NET MVC Application?

一世执手 提交于 2019-12-03 11:15:27
I have an existing ASP.NET MVC application using Visual Studio 2013. I followed this walk-through but it only concerns itself with a new greenfield project while selecting Change Authentication in project template: Developing ASP.NET Apps with Windows Azure Active Directory I am not interested in using OWIN and OpenID Connect Katana modules as these components have lots of issues so I am waiting for that technology to mature and render out all the current problems. I aim is understand how to manually add all the components and configuration to my existing ASP.NET MVC application to achieve the

ASP.NET Identity Bearer Token vs JWT Pros and Cons

帅比萌擦擦* 提交于 2019-12-03 11:13:12
问题 I have used ASP.NET Identity for a while now and have been looking at JWT (JSON Web Token) as they seem really interesting and easy to use. JWT.IO has a great example/tool of debugging the token. However, I'm not entirely sure how JWT's work on the back end, would you still use Identity? Also how do the tokens (Bearer vs JWT) compare? Which is more secure? 回答1: JWTs are like a ticket to an attraction. It contains all the security information a server needs embedded in it. Once the server has

How to change error message in ASP.NET Identity

余生颓废 提交于 2019-12-03 10:56:06
I have one question. I'm trying change error message in Identity ASP .NET and I don't know how do it. I want change error message - "Login is already taken". CreateAsync method return this error message. Please help me. The Microsoft.AspNet.Identity.UserManager<TUser> class has a public property called UserValidator of type IIdentityValidator<TUser> . The constructor for UserManager sets that property to an instance of Microsoft.AspNet.Identity.UserValidator<TUser> . The error messages you see when calling CreateAsync come from the resources embedded in the Microsoft.AspNet.Identity.dll and

'Microsoft.Owin.IOwinContext' does not contain a definition for 'GetUserManager' and no extension method?

安稳与你 提交于 2019-12-03 10:52:56
问题 The following code is copied from the Asp.Net Identity 2.0 sample. private ApplicationUserManager _userManager; public ApplicationUserManager UserManager { get { return // Error _userManager ?? HttpContext.GetOwinContext().GetUserManager<ApplicationUserManager>(); } private set { _userManager = value; } } However it gets the following error? Error 3 'Microsoft.Owin.IOwinContext' does not contain a definition for 'GetUserManager' and no extension method 'GetUserManager' accepting a first

How do I extend IdentityRole using Web API 2 + AspNet Identity 2

只谈情不闲聊 提交于 2019-12-03 10:16:10
问题 I am attempting to extend the AspNet IdentityRole class provided in the Web API 2 (With Individual Accounts) template in the latest version of Visual Studio 2013. When I hit /api/roles it returns an empty array Identity Models namespace API.Models { // You can add profile data for the user by adding more properties to your ApplicationUser class, please visit http://go.microsoft.com/fwlink/?LinkID=317594 to learn more. public class ApplicationUser : IdentityUser<string, IdentityUserLogin,

How to use Roles in user identity in MVC 5

大憨熊 提交于 2019-12-03 09:51:41
问题 I want to use asp.net useridentity in mvc 5, I do these steps: 1) create a mvc project. 2) create my own database and change the connectionstring in web.config form: to: 3) I run the project and create a new user to add related table to my database. 4) I wanted to add a role to a user after registration a user like this code in accountControler: public async Task<ActionResult> Register(RegisterViewModel model) { if (ModelState.IsValid) { var user = new ApplicationUser() { UserName = model