FAQ Database Discussion Community


How to UseCookieAuthentication OR ClaimsIdentity between ASP.NET Identity Owin site and ASP.NET WebAPI

asp.net,asp.net-web-api,asp.net-identity,claims-based-identity
I have an ASP.NET web application that is using ASP.NET Identity for login with UseCookieAuthentication in the Startup. The login site is working fine. I also have an ASP.NET WebAPI site that I use to gather data. I would like to secure the WebAPI with the same cookie that was...

User.Identity.Name or GetUserName not working on MVC 5

c#,asp.net-mvc,asp.net-mvc-5,asp.net-identity
I'm working on an MVC system where I have achieved to put the log in view as the initial page to show (like a splash screen) and once the users have successfully log in redirect them to the main view. What I need to do next is: One the users...

In MVC5 how can I create user records in code?

asp.net-mvc,vb.net,asp.net-identity,httpcontext
VS2013, MVC5, VB The MVC5 template works well to create new users from the Register View while the application is running. But if I want to create users in code, how do I do that? The following is naïve code, but demonstrates what doesn't work: Dim user = New ApplicationUser()...

Changing password asp.net identity

asp.net-mvc,asp.net-identity
Is there a quick way to verify is user exists and based on existence of user name get user id? (i.e. the user only has the user name and the adds it to change their password)? I would think something like this... String userId = User.Identity.GetUserId(userName); I am looking for...

What set's the User.Identity.Name and User.Identity.IsAuthenticated?

asp.net,asp.net-mvc,asp.net-identity,iprincipal,iidentity
I want to know what set's the user identity name and change isAuthenticatedto true. Why is User.Identity.Name an empty string and User.Identity.IsAuthenticated false after SignInManager.PasswordSignInAsync has returned Success. // POST: /Account/Login [HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task<ActionResult> Login(LoginViewModel model, string returnUrl) { if (!ModelState.IsValid) { return View(model); } var userIdentityNameTest...

User.IsInRole return false

asp.net-mvc,asp.net-identity,roles
I 'm using Identity 2 for authentication in mvc 5 web site. In my view i want check the role of the user : @if(User.IsInRole("Customers")) { @*do something*@ } but this always return false, I have already set <roleManager enabled="true" /> in the web config. any help please....

Duplicate columns in odata metadata

entity-framework,odata,asp.net-identity
I am trying to export Asp.Net Identity classes in the OData metadata. Now the the IdentityUserLogin class contains three primary keys which are not marked with [Key] attribute. When the metadata is generated, the key definition is missing in the output <EntityType Name="IdentityUserLogin"> <Property Name="LoginProvider" Type="Edm.String"/> <Property Name="ProviderKey" Type="Edm.String"/> <Property...

Trying to delete a role from Identity

asp.net-mvc,asp.net-mvc-4,model-view-controller,asp.net-identity
I am trying to delete a role from my RoleManager, and I get the error The object cannot be deleted because it was not found in the ObjectStateManager. My Controller [HttpPost] public void DeleteRole(string RoleName) { var RoleMan = new RoleManager<IdentityRole>(new RoleStore<IdentityRole>(new ApplicationDbContext())); IdentityRole Role = new IdentityRole(); Role.Name =...

Integrating Windows Authentication with ASP.NET and Drupal In External Portal

asp.net,drupal,single-sign-on,asp.net-identity,windows-authentication
We are in the final stages of developing a portal application, built in ASP.NET MVC, for a large organization with many subsidiaries. The portal will be used by both internal, meaning employees of the organization, and external users. The portal also has an accompanying informational CMS that is being developed...

Thinktecture multiple website connect ( SSO )

asp.net-mvc,asp.net-identity,thinktecture-ident-server
I just started exploring Thinktecture becuase i have multiple websites and i want Single Sign On between them . So , i started working on this and i am following this tutorial Thinktecture tutorial Every thing works fine following this tutorial , when i added another application in my same...

MVC 5 Identity 2.0 lockout doesn't work

c#,asp.net-mvc,asp.net-identity,lockout
I need to block a user permanently. I don't understand why this code is not working. This line UserManager.IsLockedOut(user.Id); always returns false instead of true. Maybe it's necessary to put this line UserManager.UserLockoutEnabledByDefault = true; in user registration stage? using (var _db = new ApplicationDbContext()) { UserStore<DALApplicationUser> UserStore = new...

How can I connect the ASP.NET Identity database with my own database?

asp.net,entity-framework,asp.net-identity,code-first-migrations
I want to have all the tables in one place, something like the situation in this question. Which migrations should I run and how?

This Identity Bearer token is not being recognized

c#,asp.net,asp.net-identity
I'm following this tutorial for learning to use Identity. Helpfully, the author offers a working example of his code on his own server. I have made this console application that does the following: Register an account. Retrieve a token for this account. Retrieve information with this token. using System; using...

Simple Injector Identity UserManager Registration Error

c#,asp.net,dependency-injection,asp.net-identity,simple-injector
I am following Onion Architecture and using Identity Framework. In my Core project, I have: public interface IUserRepository : IDisposable { // Repository methods....... } In my Architecture.Repository, I have public class UserRepository : IUserRepository { // This is Identity UserManager private readonly UserManager<AppUser, int> _userManager; private readonly IAuthenticationManager _authenticationManager;...

Asp.Net Identity find users not in role

asp.net,linq,entity-framework,asp.net-identity
I need to find all users that DONT'T contain a certain role, using Asp.Net Identity. So far I have something like this but it is not working. (From role In context.Roles From userRoles In role.Users Join us In context.Users On us.Id Equals userRoles.UserId Where role.Name <> "SomeRole" Select us.UserName) This...

How to use Windows Active Directory Authentication and Identity Based Claims?

authentication,asp.net-identity,claims-based-identity,asp.net-5,visual-studio-2015
Problem We want to use Windows Active Directory to authenticate a user into the application. However, we do not want to use Active Directory groups to manage authorization of controllers/views. As far as I know, there is not an easy way to marry AD and identity based claims. Goals Authenticate...

Asp.net MVC 5 can't get user roles

asp.net,asp.net-mvc,asp.net-membership,asp.net-identity
I'm trying to get user roles and modify it. I've tried many ways to get user roles but nothing works. Is there anything missing? I can get right User entity but Roles is always null. Is there any way to do it correctly? Thanks var user = UserManager.Users.Single(u=>u.Id==id); var roles...

ASP.NET Identity User ID to Int error Conversion failed nvarchar Value

c#,asp.net,entity-framework,asp.net-identity,dbcontext
My code was working fine but when i tried to make the User ID as Int rather then string by adding in application user and in all classes. The add-migration works fine but upon update-database i get the following error. Conversion failed when converting the nvarchar value '60b67a91-64e0-4dc7-a85c-abd9521a0b50' to data...

Where does EntityFramework get the connection string to my local database?

c#,entity-framework,asp.net-identity
I have created a web form that is a registration form using Identity. The form calls code behind that looks like this: protected void CreateUser_Click(object sender, EventArgs e) { var userStore = new UserStore<IdentityUser>(); var manager = new UserManager<IdentityUser>(userStore); var user = new IdentityUser() { UserName = UserName.Text }; IdentityResult...

MVC Identity 2 - Logout on browser or tab close

asp.net-mvc,asp.net-identity,asp.net-identity-2
I need to log out a user if he closes the browser/tab running my website. I have set the isPersistant bool to false, yet it does not log the user out. I want force the user to log in again if the tab is closed, I don't want to use...

ASp.Net Identity Role manager

asp.net,vb.net,webforms,sql-server-2012,asp.net-identity
I am using Visual Studio 2013. I have a ASP.net (vb) Webforms site with asp.net identity. I trying to create a page that manages User role and create roles. I cant find any help online for this when it comes to web forms. This code works for asp.net membership but...

Dynamically add roles to authorize attribute for controller

c#,asp.net,asp.net-mvc,asp.net-identity,authorize-attribute
I need to enable my admin user to change access permissions for users on the fly, such that they can create new Roles and add permissions to those Roles. I want to be able to create an Authorize attribute to stick above my controller clas that I can add roles...

Can't find user (social login) with FindAsync(UserLoginInfo)

c#,asp.net-identity,asp.net-identity-2
My app uses social login providers (facebook and linkedin) and asp.net Identity for membership. The below code creates the user IdentityUser user = new IdentityUser(username); IdentityResult identityResult = await _repo.CreateAsync(user); I should then expect to be able to find the user with the following call IdentityUser user = await _repo.FindAsync(new...

can't remove user claim in asp Identity

asp.net,asp.net-web-api,asp.net-identity,claims
i Try to update user claims in my service and at the first i should remove claims like this: var userClaimCollection = this.AppUserManager.GetClaims(user.Id); var toRemove = new List<Claim>(); foreach (var claim in userClaimCollection) { if (claim.Type == group_role) { toRemove.Add(claim); } } foreach(var t in toRemove) { Claim c =...

How to get user profile data from ASP.NET MVC custom IdentityUser Model?

c#,asp.net,asp.net-mvc,asp.net-membership,asp.net-identity
With the help of this blog, I have added a custom profile property OfficeKey to ApplicationUser class (in IdentityModels.cs file): public class ApplicationUser : IdentityUser { public int OfficeKey { get; set; } //remaining code here } I can get user name like this: User.Identity.Name How do I get custom...

MVC5 ASP Identity dynamic Authorize attribute

c#,asp.net-mvc,authorization,asp.net-identity,authorize-attribute
I have a MVC5 project with backend to configure which role can access which menu. The normal way to implement role based authorization is something like this. [Authorize(Roles="Admin")] public ActionResult UpdateProduct(ProductModel model) { //do something return View(model); } Because I need the roles to be dynamic, I was thinking of...

ASP.NET Identity with db on cloud server

c#,asp.net-mvc-5,asp.net-identity
I created a new MVC5 project with Identity and it makes its own db which i want to change with same one but mine and on cloud server. so i have 2 connection stings and the only things that i changed was table names ex: aspnetUser to CJUser and so...

InitializeIdentityForEF freezes and does not create the default admin account

asp.net,asp.net-mvc,entity-framework,asp.net-identity
When I first started the project, I had no errors. Now, when I run the project and it creates the database, it keeps loading and loading. If I stop and run again, everything works fine, except my admin account was not created. I'm using Identity 2.0. Here is the code:...

Identity ApplicationDbContext with ninject

asp.net-mvc,entity-framework,asp.net-identity
I am using ninject for my entities and have created a custom dbcontext, which holds my poco classes. This is CusDbContext . I then add *this to identity by adding it as a parameter in the base class constructor for ApplicationDbContext public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext() :...

asp.net identity tables location

c#,asp.net-mvc,asp.net-mvc-5,asp.net-membership,asp.net-identity
I'm working on mvc5 project which is using asp.net identity for membership provider. Now, I've registered the first test user via web interface and I was expecting to see newly created tables in the db I'm using but there are no new tables created although I'm able to register/login/logout of...

Entity Framework using Identity - Trying to update a user in the AspNetUsers table

asp.net-mvc,entity-framework,asp.net-identity
I am having a hard time figuring out how to update/modify a user in my AspNetUsers table using the Entity Framework and Identity. I am getting an error that says: "The entity type ManagerUserViewModel is not part of the model for the current context." This make sense, because I do...

Adding entity to Identity model

c#,entity-framework,asp.net-mvc-5,asp.net-identity
I am currently getting an error I understand the error but I don't know where I am going wrong The ALTER TABLE statement conflicted with the FOREIGN KEY constraint "FK_dbo.AspNetUsers_dbo.CompanyDetails_userCompanyID". The conflict occurred in database "PXWHITESPIDERDEV", table "dbo.CompanyDetails", column 'companyID'. Within the IdentityModel autogenerated when you create an MVC application...

Is it considered bad practice to reference the Microsoft.AspNet.Identity in the service layer of a multi layered web application?

c#,asp.net,asp.net-mvc,security,asp.net-identity
In my MVC application I am currently setting the Thread.CurrentPrincipal = HttpContext.Current.User in the Application_PostAuthenticateRequest() method e.g. protected void Application_PostAuthenticateRequest() { Thread.CurrentPrincipal = HttpContext.Current.User; } This allows me to use the Thread.CurrentPrincipal in other assemblies i.e. the service layer. For example: using System.Security; using System.Security.Permissions; using System.Threading; using Microsoft.AspNet.Identity; namespace...

How i can inject context from UnitOfWork using StructureMap

c#,asp.net-mvc-5,asp.net-identity,structuremap,unit-of-work
Hi i have mi project in MVC5, i am using Identity 2.0, commonRepository and Structuremap to inject dependencies, the problem is when I am in the controller AccountController, i have one Contex and when my UnitOfWork inject the repositories it create other Instance. how I can inject or replace the...

How to remove dbo.AspNetUserClaims and dbo.AspNetUserLogins tables (IdentityUserClaim and IdentityUserLogin entities)?

c#,asp.net-mvc,entity-framework,asp.net-identity
Our application doesn't need the excessive "Logins" and "Claims" functionality that identity uses. It would be nice if these tables simlpy didn't get created in the database, but I don't want to have to reimplement all identity classes... I'd assume it's something like public ApplicationDbContext : IdentityDbContext { [...] protected...

How to send email to registered user (MVC)

asp.net-mvc,email,asp.net-identity
My problem is this one, I have users that are registered in a basic MVC 5 application, when they register they provide email address and a username. In the application userA can see what userB created (ie a product or whatever), what I want to do is that for userA...

How to Pass User Roles to View as ViewModel in ASP.NET MVC?

asp.net-mvc-5,asp.net-identity
An admin should be able to create a user and select which role the user belongs to. My CreateUserViewModel looks like: pubic class CreateUserViewModel { public string Id { get; set; } public string Name { get; set; } public List<ApplicationRole> Roles { get; set; } } My controller action...

ASP.NET MVC Blacklist for Roles/Users

c#,asp.net,asp.net-mvc,asp.net-identity,authorize-attribute
Question Summary: In ASP.NET MVC, is there a clean way to prevent a specific user or role from accessing an action? Obviously, the following would allow roles Admin and Editor to access the entire controller. [Authorize(Roles = "Admin, Editor")] public class HomeController : Controller { public ActionResult Index() { return...

ASP.NET Identity : Prevent the user to Sign In without email confirmation

asp.net-mvc,asp.net-identity
Is there any built in way in ASP.NET Identity to prevent user to log in if he hadn't confirm his email? Currently in my application I can create a new user and be able to sign in without confirming the email. Is there any configuration or something that I have...

Send connection string to ApplicationDBContext

c#,asp.net-mvc-5,asp.net-identity,owin
I have customized the ApplicationDBContext class to receive a connection string via its constructor. It can connect to the database OK when called directly however when called through the app.CreatePerOwnContext I am unable to call it. My class definition is below: public class ApplicationDbContext : IdentityDbContext<ApplicationUser> { public ApplicationDbContext(string databaseConnection)...

Asp .NET Identity Cookie Authentication

authentication,asp.net-identity
I'm using MVC 5 default template with "Individual Accounts" selected for authentication. it uses ASP .NET Identity with Entity Framework. Using Chrome I opened the app and Registered a user and then login with the user. I accidentally deleted the database. Now when I open the app again in Chrome...

Role-based Security Authorization in web froms using Identity 2.0

c#,asp.net,webforms,asp.net-identity,asp.net-identity-2
I've seen not hundred but THOUSANDS of example where from scratch to complete examples with MVC identity 2.0 are done but not a single one with bloody web forms and the one which are present are not even worth while just very basic. I'm working on an application where I've...

ASP.NET Web Forms and Identity: Move IdentityModels.cs to another project

c#,asp.net,.net,webforms,asp.net-identity
I'm trying to move IdentityModels.cs to another project to keep the web site apart from the Data Access Layer. I followed this tutorial: http://blog.rebuildall.net/2013/10/22/Moving_ASP_NET_Identity_model_into_another_assembly And also checked this question here: How to move MVC 5 IdentityModels.cs into a separate assembly But I'm still confused because IdentityModels references another class called...

Add user roles and map these with users

c#,asp.net-identity
I am working on an authentication with ASP.NET Identify and Web API. I have this code: public async Task<IdentityResult> RegisterUser(UserModel userModel) { IdentityUser user = new IdentityUser { UserName = userModel.UserName, }; var result = await _userManager.CreateAsync(user, userModel.Password); return result; } In the AuthContext I added these roles with these...

Using EF and other Dapper ORM in same project - drawbacks [closed]

asp.net,asp.net-mvc,asp.net-identity,projects-and-solutions,dapper
I am about to start a new project and I have a little dillema. App require asp identity for security and dapper as orm. My plan is to use default asp web app template with identity that use entity framework and for all business data access use dapper. This means...

Best practices when configuring relying party for on-premise authorization

active-directory,asp.net-identity
I've created a website within the company that utilizes our active directory server to authenticate. I am concerned about security surrounding setting up relying parties with "localhost" domains. I've pretty much followed this guide on setup. You'll notice about halfway down the page, there is a step to set up...

Temporarily Changing Identity with WebApi 2

c#,asp.net-identity,owin,claims-based-identity
I have a WebApi controller that initially authenticates as a specific WebApi user. Subsequent accesses to the web api will pass a user that operations should be performed as, without having to actually authenticate as that user. I have some services/managers that perform functions as those proper users as part...

HttpContext.Current.User.Identity on AuthenticationManager.SignIn

asp.net-mvc,asp.net-identity
I am using ASP.Net Identity to manage my users. I am finding that after calling the following: AuthenticationManager.SignIn(new AuthenticationProperties { IsPersistent = isPersistent }, identity); when I check if the user is currently authenticated via HttpContext.Current.User.Identity.IsAuthenticated it returns false. I managed to get this to return true by doing the...

Identity Framework create a new password for a user (without a password)

c#,asp.net-web-api,asp.net-identity
So, I have this site where users can only be created by administrators. I set up my Web API method like this: /// <summary> /// Creates a user (with password) /// </summary> /// <param name="model">The bound user model</param> /// <returns></returns> [HttpPost] [Route("")] public async Task<IHttpActionResult> CreateUser(UserBindingModel model) { // If...

Asp.NET MVC Identity with MySql register error

c#,xml,asp.net-mvc,entity-framework,asp.net-identity
I'm using for the first time Identity to make the user registration. I need to be registered but this returning me a mistake and I do not know what can be used as a model a project that tested and is working, but with some differences, we are using MySql:...

Identity 2.1 - Remove from all previous roles, then add to specific role? Plus error in calling UserManager when doing so

asp.net-mvc,asp.net-identity
I am writing a user manager for a system administrator where you can perform various functions on the user object. My current dilemma is I want to be able to write something like await UserManager.RemoveFromRoleAsync(userID, any); and have that person removed from all previous roles. Right now I've written this...

Roles.GetRolesForUser() in Layout view not returning roles

asp.net,asp.net-mvc,asp.net-identity,asp.net-identity-2
@Roles.GetRolesForUser() in razor layout view is not returning roles. @Roles.GetRolesForUser().Count() is 0. While @Roles.IsUserInRole('name_of_logged_in_role') returns true in the same view at the same place. Razor View: <p> @User.Identity.Name //Output: MyName @Roles.GetRolesForUser().Count() //Output: 0 @Roles.IsUserInRole("Radiologist") //Output: True </p> Update @Roles.GetRolesForUser(User.Identity.Name).Length //Output: 0 @Roles.GetRolesForUser(User.Identity.GetUserName()).Length //Output: 0 ...

Adding User Authentication to MVC

asp.net,asp.net-mvc,entity-framework,asp.net-identity
I was assigned my first ever MVC 5 projet, it is a simple Lending System with lots of CRUD operations which is almost done except that I have not implemented user authentication to the app yet. My project has 4 layers: 1. App.Web - mvc web app 2. App.DataAccess -...

ASP NET Identity Manager database permissions

c#,asp.net,sql-server,asp.net-identity,identity-management
I have got Identity Manager set up and running locally, working with ASP.NET Identity. I have a SQL Server 2012 database for the backend. I can create a user and get a list back, however whenever I try and create a role, edit a user or list the roles i...

Find user by custom property identity asp.Net mvc

c#,asp.net-mvc-5,asp.net-identity
I am trying to find an user that has a custom property "Token" that I added with database migration, I tried to use: var adb = new AppDbContext(); var found = adb.Users.Where(u => u.Token == "ABDJ_SJ_ETC");//Error //OR found = adb.Users.SingleOrDefault(); Error too My AppDbContext class AppDbContext.cs namespace MyApp{ public class...

Many to many relationship between AspNetUsers (Identity) and other tables in a custom database

c#,asp.net,entity-framework,webforms,asp.net-identity
I'm starting to learn ASP.NET and I followed this tutorial. So, I got a simple app which uses the ASP.NET Identity membership system and has an additional database containing products and cart items. Is there a way for creating a many-to-many relationship between the users and the products data, considering...

How to define multiple partial Owin Startup classes and have them all run their code

asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-identity,owin
I'm working on an MVC application that will feature a "plugin" architecture. Basically there will be a main "host" project that will dynamically load other projects at runtime. We want to move all ASP.NET Identity related stuff into its own separate plugin project. The main host project already contains an...

ASP.Net Identity Framework sign in after register

asp.net,asp.net-mvc,asp.net-identity
I have the following code to try and automatically log a user in after they register but for some reason it doesn't work. The code hits the line: return RedirectToAction("Index", "Home"); But for some reason still doesn't log the user in. I thought the SignInAsync would have done it. Anyone...

Updating records using a Repository Pattern with Entity Framework 6

c#,asp.net-mvc-5,entity-framework-6,asp.net-identity,repository-pattern
I'm writing a simple blog application and trying to establish CRUD operations in my generic repository pattern but I'm getting an error on my update method that says: 'System.Data.Entity.DbSet' does not contain a definition for 'Entry' and no extension method 'Entry' accepting a first argument of type 'System.Data.Entity.DbSet' could be...

What is the purpose of ASP.NET's machine key validation key

asp.net,security,asp.net-identity
In ASP.NET 4, the default hashing algorithm was changed to HMACSHA256. I know the decryption key is used in forms authentication and for the new ASP.NET Identity cookie authentication. Is the validation key used for anything other than Viewstate validation in Web Forms? Reason I ask is that we use...

Get current ApplicationUser in layout view

asp.net-mvc,asp.net-identity
I am using MVC5, created ApplicationUser : IdentityUser with custom properties. Now I want to get a custom property (Avatar) in layout.cshtml to show the logged in user image in different layout (header, sidebar) views. How do I do that? public class ApplicationUser : IdentityUser { public string Avatar {...

How to speed-up user search in ASP.NET Identity?

mysql,asp.net-mvc,asp.net-identity
I have an ASP.NET MVC 5 application, and I'm using MySQL database. Currently, I'm working on my local development environment, so I'm working from my localhost for the website, and using my local MySQL database. I have nearly 1 million users in my aspnetusers table. The problem is, when I...

How to secure IdentityManager with IdentityServer v3

asp.net,asp.net-identity,thinktecture-ident-server,thinktecture,identityserver3
Brock Allen released the new beta version of IdentityManager last week. There are quite some changes in the security model, so the configuration also changed. He even took some videos (Setting up ASP.NET Identity and Security and IdentityManager) on how to configure the new version properly. These well explain the...

Validation of asp.net identity password

c#,asp.net,.net,asp.net-mvc,asp.net-identity
I have an asp.net mvc application, in which I used the Asp.net identity. I implemented this method to validate a collaborator ( customisation of user) fields : [HttpPost] public bool ValidateCollaborateur(CollaborateurModel item) { if (item.Username == null || item.Email == null) return false; if (UserManager.FindByEmail(item.Email) != null) return false; return...

Why does this violate the type constraint?

asp.net,asp.net-identity,type-constraints,asp.net-identity-3
I'm trying to customise ASP.NET Identity 3 so that it uses integer keys: public class ApplicationUserLogin : IdentityUserLogin<int> { } public class ApplicationUserRole : IdentityUserRole<int> { } public class ApplicationUserClaim : IdentityUserClaim<int> { } public sealed class ApplicationRole : IdentityRole<int> { public ApplicationRole() { } public ApplicationRole(string name) { Name...

Losing HttpContext with async await in ASP.NET Identity GetRolesAsync

c#,asp.net-web-api,async-await,asp.net-identity
This is more of an async/await question than ASP.NET Identity. I am using Asp.Net Identity, and have a custom UserStore, with a customized GetRolesAsync method. The UserManager is called from a WebApi controller. public class MyWebApiController { private MyUserManager manager = new MyUserManager(new MyUserStore()); [HttpGet] public async Task<bool> MyWebApiMethod(int x)...

How to get the current logged in user Id ASP.NET MVC6

asp.net,asp.net-identity,asp.net-mvc-6
I've done this before with MVC5 using User.Identity.GetUserId() but that doesn't seem to work here. The User.Identity doesnt have the GetUserId() method I am using Microsoft.AspNet.Identity...

Bug in ASP.NET Identity's UserManager

asp.net-mvc-5,asp.net-identity
MVC5's UserManager seems to have a bug: My Code: public void InsertUser(KoreUser user, string password) { var appUser = new ApplicationUser { UserName = user.UserName, Email = user.Email, LockoutEnabled = user.IsLockedOut }; userManager.Create(appUser, password); } THis code works perfectly fine in almost all cases.. the exception being when the UserName...

MVC5 Identity Seed Users in database

asp.net-mvc-5,asp.net-identity
I am getting an error that says: "UserId not found." when trying to seed multiple users into my database. Here is my seed method: protected override void Seed(newBestPlay.Models.ApplicationDbContext context) { // This method will be called after migrating to the latest version. InitialCreate create = new InitialCreate(); create.Down(); create.Up(); context.Configuration.LazyLoadingEnabled...

Configure the authorization server endpoint

c#,asp.net,oauth,asp.net-identity,asp.net-5
Question How do we use a bearer token with ASP.NET 5 using a username and password flow? For our scenario, we want to let a user register and login using AJAX calls without needing to use an external login. To do this, we need to have an authorization server endpoint....

In Asp.Net 2.0 Identity as I have only enable a role to log in a aplication? [closed]

c#,asp.net,asp.net-mvc,asp.net-identity
in login enable one role for login. var result = await SignInManager.PasswordSignInAsync(model.Email, model.Password, model.RememberMe, shouldLockout: false); return error if login not are in role. The some way to do this using the Asp.Net 2.0 Identiy ?...

How do I plug a custom roles manager into the AuthorizeAttribute?

asp.net-mvc,asp.net-identity
I have an older database schema that I cannot change. It has a single user table with an integer field to designate user level where 1 is standard user and 5 is administrator. I'm writing an MVC front end and I want to use ASP.NET Identity. I've figured out everything...

What is the syntax for creating an instance of UserManager actually doing?

vb.net,asp.net-mvc-5,asp.net-identity
VS2013, MVC5, VB I was helped to solve a problem for creating users in my seed method for an MVC5 application at this post. This question is to ask what is going on with this line of code that is working correctly: Dim myUserManager = New UserManager(Of ApplicationUser)(New UserStore(Of ApplicationUser)(New...

EF seed method does not save custom Identity user

entity-framework,asp.net-web-api,asp.net-identity
Using this Tutorial I try to implement Identity System in my web API Application, So i customize UserIdentity And UserManager and in Seed method of EF, Try to generate sample data Like This: var manager = new UserManager<ApplicationUser>(new UserStore<ApplicationUser>(new MedicalContext())); var appUsers = new List<ApplicationUser> { new ApplicationUser{FirstName="admin",LastName="admin",UserName="admin",Email = "[email protected]",EmailConfirmed...

Where is the asp.net identity 2.2.1 Source code?

asp.net-identity
Where is the asp.net identity 2.2.1 Source code? I have found 2.1 here: https://aspnetidentity.codeplex.com, and vNext here: https://github.com/aspnet/Identity but I am using 2.2.1 and need the source for that.

How to get the selected DDL value from a row in ListView

c#,asp.net,listview,asp.net-identity
right now I am just trying to put together a simple role assigning pages in ASP.NET, I have created a listview, and in my item template I have a drop down list, with a button in the same template. The DDL is hooked up to an ODS which gets me...

How to create a custom asp.net identity provider with SQL Server? [closed]

c#,asp.net,azure,asp.net-identity,claims-based-identity
The scenario I have is the following, I am going to create a software as a service application hosted in azure, where all users will be able to login with a username and password, the SQL identity provider seems a good option but I need something custom. The software would...

ReturnForAnyArgs without using NSubstitute

mocking,asp.net-identity,owin,nsubstitute
I am unit testing a Post method that in its implementation uses a Microsoft.AspNet.Identity.Owin.SignInManager because SignInManager inherit from a class and not an interface I cannot use NSubstitute to mock the SignInManager object. Therefore I cannot use the ReturnForAnyArgs method to get it to return a SignInStatus of say Success....

How to change PasswordValidator in MVC6

asp.net-mvc,asp.net-identity,asp.net-5,asp.net-mvc-6
In the Asp.Net MVC 5 using Identity, was possible to do the following: manager.PasswordValidator = new PasswordValidator { RequiredLength = 6, RequireLowercase = true, RequireDigit = false, RequireUppercase = false }; How to change the same configuration in MVC 6? I see that can be in ConfigurationServices method in the...

Implement OWIN Authentication in Existing MVC 5 app

c#,asp.net-mvc-5,asp.net-identity,owin
I am currently struggling to understand how exactly the OWIN Authentication works within MVC 5. I have read numerous articles, but it all seems as if they expect you to know quite a bit about this. I want to implement Authentication in my MVC 5 app, but have not yet...

asp.net identity with custom role

c#,asp.net,asp.net-identity
I have problem with Identity framework and custom role. My custom role contains a set of activity permission. My custom role look like public class MyRole : IdentityRole { public List<MyPermission> Permissions { get; set; } } public class MyPermission { public int Id { get; set; } public int...

Show all roles in View with Identity

asp.net-mvc,entity-framework-4,asp.net-identity
I'm trying to show all roles existing in the DB. So in my controller i got this : public ActionResult RoleIndex() { foreach (string role in Roles.GetAllRoles().ToList()) { System.Diagnostics.Debug.WriteLine(role); Console.Write(role); } return View(); } It show all the roles so it's good. But now i want to show this in...

Store does not implement IUserLockoutStore

asp.net-mvc-5,asp.net-identity
I'm trying to implement own DAL for asp.net Identity 2.0 with functionality that I need. I don't need Account Lockout functionality. But When I try to call var result = await SignInManager.PasswordSignInAsync(model.Login, model.Password, model.RememberMe, shouldLockout: false); I get System.NotSupportedException:Store does not implement IUserLockoutStore<TUser>. So why should I need to implement...

What's the best way to perform CRUD with ASP.NET Identity?

asp.net-mvc-5,asp.net-identity
By default, ASP.NET MVC's implementation of Identity for authentication does not support full CRUD operations for it's users. I know it already has: Register, Login, Manage, and Change Password But the problem is that doesn't have: Account Update or Edit, Select User Role, and Delete User I think that Identity...

Configure a custom store in ASP.NET Identity 2.x

c#,asp.net,configuration,asp.net-identity,owin
I've already developed an implementation to the following ASP.NET Identity interfaces: IUserLoginStore<TUser>, IUserClaimStore<TUser>, IUserRoleStore<TUser>, IUserPasswordStore<TUser>, IUserSecurityStampStore<TUser>. Furthermore, I'm using OWIN/Katana, so I need to configure this by code during startup. How do I provide/configure my custom store implementation to ASP.NET Identity? Note: I've been searching a simple and clear tutorial...

Implementing UserManager to use a custom class and Stored Procedures

.net,asp.net-mvc,asp.net-identity,asp.net-identity-2
All of the authentication and authorization process of my app is done using stored procedures. I've written a class with all of functionalities that I need, e.g. GetUsers, Login, AddRole, AddMember, etc. Also the admin page for managing users and roles and permissions is done by using this class. I...

ASP.NET Identity and Claim-based

c#,asp.net-mvc,asp.net-identity,claims-based-identity,claims
How to use claims? For example, I want to set access to each page (resource) for each user. I understand, I can do it using roles, but as I understand, claim-based is more effectively. But when I try to create a claim, I see the following method: userIdentity.AddClaim(new Claim(ClaimTypes.Role, "test...

Onion Architecture Identity Framework

asp.net,.net,asp.net-web-api,asp.net-identity,onion-architecture
I am following Onion Architecture. And in that I am using ASP.NET Identity Framework. Here is my Project Structure: 1-Core - Domain Classes //It contains my T4 template classes -- AppUser //It is Identity User. - Repository Interfaces - Service Interfaces 2-Infrastructure - Data //It contains my edmx file, I...

How to tell if user logged in via Facebook

asp.net,asp.net-identity,asp.net-identity-2
Simple version of this question: how can I tell if a user is authenticated through Facebook after they are logged in with ASP.NET Identity? VS2013, ASP.NET SPA Template, ASP.NET Identity 2.2.1: I'd like to know if a user authenticated via Facebook. I was previously able to do this call: ExternalLoginData...

Implement ASP.NET Identity IUserLockoutStore without IUserPasswordStore

c#,asp.net-mvc,asp.net-identity
I have MVC5 project and I don't have direct access to user database instead I was provided with web services, for example: bool register (string username, string password, string email) //password is plain text bool login (string username, string password) My problem is that I have no idea how to...

When will VerifyHashedPassword result be SuccessRehashNeeded

asp.net-identity,asp.net-identity-2,aspnet-identity
When will the result of Usermanager.VerifyHashedPassword result be PasswordVerificationResult.SuccessRehashNeeded ? What to do if such result occur? When using VerifyHashedPassword i only check it with Success. Is it enough or should i check it with Failed?...

ASP.NET Identity 2.0 decrypt Owin cookie

asp.net,asp.net-mvc,wcf,cookies,asp.net-identity
I'm working in a server-side application where I'm applying multi tenancy. In this server side I have a Backoffice (ASP.NET MVC) and a BackEnd (WCF). I want to decrypt Identity cookie so that I can check that it is valid and use it to auth in WCF Services. To be...

AuthenticationManager.GetExternalLoginInfoAsync() always null

c#,asp.net-identity,asp.net-identity-2
ExternalLoginInfo loginInfo = await AuthenticationManager.GetExternalLoginInfoAsync(); Why must this line always return null? It happens when the user tries to login using ANY provider. I know the FLOW is correct because actually it works locally, but when I deploy the website it always returns null. From what I understand it's using...

UserManager VerifyUserTokenAsync Always False

asp.net-mvc,asp.net-identity,asp.net-identity-2
I'm generating a usertoken like so public async Task GenerateCode() { var code = await UserManager.GenerateUserTokenAsync("heymega", new Guid("16139fcd-7ae0-449c-ad1c-f568bbe46744")); } I then pass the same token into another action via a separate request public async Task ValidateCode(string code) { var valid = await UserManager.VerifyUserTokenAsync(new Guid("16139fcd-7ae0-449c-ad1c-f568bbe46744"), "heymega", code); //Returns False } However,...

EF6 Migrations MVC5 Identity 2.1 - Multiplicity is not valid in Role

c#,sql-server,asp.net-mvc,entity-framework,asp.net-identity
I basically have a new MVC5/EF6 (individual user authentication) project and I'm trying to slightly modify the Identity Users table to include an Id for Country, State and City. I was able to create the new columns successfully through EF Migrations, but upon trying to add the FK constraints I...

Asp.net identity - How to maintain logged in user role?

c#,asp.net,angularjs,asp.net-identity,identity
I m using Angularjs project and using Asp.net identity custom storage provider with Enterprise library for token authentication. Implemented custom userstore to create an account. [Authorize] attribute works well after logged in. i want to restrict the method for particular user. So tried to implement [Authorize(Roles="Admin,User")]. Here one user can...

Invalidate user credentials when password changes

asp.net,asp.net-mvc,security,asp.net-identity
I have an Asp.net MVC website. When the users change their password, do the logins from all of the browsers invalidate? I mean will the user require to login on all browsers with the new password? If not, is there a way to do this?

Identity 2.1 - Check for existing role, default to base user if not in role

c#,asp.net,asp.net-identity
I am working with this controller code in c#, MVC, and ASP.NET Identity: var role = (from r in context.Roles where r.Name.Contains("SuperAdmin") || r.Name.Contains("ReadOnlyAdmin") select r).FirstOrDefault(); var roleusers = context.Users.Where(x => x.Roles.Select(y => y.RoleId).Contains(role.Id)).ToList(); if (roleusers.Find(x => x.Id.Equals(userDetails.Id)) != null) { await UserManager.AddToRoleAsync(userDetails.Id, "User"); } The goal is to have...

How to implement a relationship between IdentityRole (dbo.AspNetRoles) and a custom entity?

c#,asp.net-mvc,entity-framework,asp.net-identity
I'm working with a project similar to the MVC template project. I've created some models that I want to be represented in the database. I can create them with a DbContext class just fine, the issue is connecting my class's RoleId with ASP.Net Identity's Role table's id. Any ideas as...

How to migrate from SimpleMembership to ASP.NET.Identity

asp.net-mvc-4,asp.net-mvc-5,asp.net-identity,simplemembership
Migrating from MVC4 to MVC5 and want to use ASP.NET Identity too but I am struggling to find anything that covers everything I think I need to do to migrate the Identity. This link suggests all I need to do is create an ApplicationUser and migrate the data, and other...