FAQ Database Discussion Community


Validate username and password without authenticating the user

asp.net-web-api,asp.net-identity-2
Using Asp.Net Identity 2.x with WebApi 2.x (both latest), is it possible to just validate a given username and password in order to know if the provided information is valid, without actually authenticating the user? I am working on a partial login in our identity service and it's essential that...

ASP Identity 2 + Web API Token Auth - Persistent claims not Loading

c#,authentication,asp.net-web-api,asp.net-identity,asp.net-identity-2
Im having some trouble with claims in ASP.NET Web API Token Auth. Essentially I have created a user with some claims (values are being stored in the AspNetUserClaim table) but when the users identity is created, those claims are not being pulled from the database. A breakdown of my setup...

How to add claims during user registration

c#,asp.net-mvc,asp.net-mvc-5,asp.net-identity-2
I'm using ASP.NET MVC 5 project with identity 2.1.0 and VS2013 U4. I want to add claims to user during registration in order to be stored in db. These claims represent user custom properties. As I created a web page for administrator to create/edit/delete users, I'm still using create method...

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 ...

Get ApplicationUser from Partial View

c#,asp.net-mvc,asp.net-identity-2,asp.net-mvc-6
I have asked similar question about older MVC version and Membership, but those solutions don't work with Idendity and MVC 6. I want to display user's first name inside _LoginPartial.cshtml file. So, instead of "Hello " + User.Identity.GetUserName() + "!" I want to access ApplicationUser.FirstName for the currently logged in...

MVC Identity 2 using FormsAuthenticationTicket

asp.net-mvc-5,forms-authentication,asp.net-identity-2
I am replacing the (HttpContext.Current.User) IPrincipal with a custom version so I can store more information login and the user. I have done this before using the FormsAuthtenticationTicket, but those other ways were based on the Memberhipship and SimpleMembership providers. My question is, can i use the FormsAuthenticationTicket to store...

Ninject ASP.NET Identity The type '…' cannot be used as type parameter 'TImplementation' in the generic type or method

c#,dependency-injection,asp.net-identity-2,ninject.web.mvc
I'm getting a few compiler errors about my bindings with Ninject. This is the code: kernel.Bind<IUserStore<ApplicationUserStore>>().To<UserStore<ApplicationUser, ApplicationRole, int, ApplicationUserLogin, ApplicationUserRole, ApplicationUserClaim>>().InRequestScope(); kernel.Bind<IRoleStore<ApplicationRoleStore>>().To<RoleStore<ApplicationRole, int, ApplicationUserRole>>().InRequestScope(); And these are the compiler errors: Error 5 The type 'MyNamespace.Data.ApplicatonRoleStore'...

Web API 2 identity. /Token Always return 404 error

asp.net,asp.net-web-api2,asp.net-identity-2
I have some problems with adopt Web API 2 Identity. In project. I add StartUp.cs Like this: using Microsoft.Owin; using Owin; [assembly: OwinStartup(typeof(MyNamespace.Startup))] namespace MyNamespace { public partial class Startup { public void Configuration(IAppBuilder app) { ConfigureAuth(app); } } } After that I add partial class for enable Token authorization:...

Asp.Net Identity is hosted both on Github and CodePlex. Which one is the official one?

asp.net,asp.net-mvc,open-source,asp.net-identity,asp.net-identity-2
As I search for the source code of Asp.Net Identity, the project can be found on both github and codeplex. The problem is that both seem to be the main repository. Which one is the correct one?

Should I separate my application context from ApplicationDbContext used for identity?

c#,asp.net,entity-framework,dbcontext,asp.net-identity-2
In Visual-Studio 2013, when creating an ASP.NET project, it generates a file IdentityModels.cs that contains a class ApplicationDbContext, that inherits from IdentityDbContext<ApplicationUser>, which eventually inherits from DbContext. Should I keep this context only for account-related entities, and created a separate context for all the other entities in the application or...

ASP.Net MVC 5 w/identity 2.2.0 Log off not working

asp.net-mvc,asp.net-mvc-5,asp.net-identity-2
I am using a the basic login on a test ASP.Net MVC 5 site (for an internet site). The login works fine but when I try to logout it doesn't happen. The logout link does call the following controller action: public ActionResult LogOff() { AuthenticationManager.SignOut(); return RedirectToAction("Index", "Home"); } But...

Relating tables to a Microsoft Identity User - has no key defined errors

c#,asp.net,asp.net-mvc-5,asp.net-identity-2
I have followed the following and used ApplicationUser instead of creating my own. ApplicationUser comes from the default MVC 5 application: http://blogs.msdn.com/b/webdev/archive/2013/10/20/building-a-simple-todo-application-with-asp-net-identity-and-associating-users-with-todoes.aspx This is my ApplicationUser code: public class ApplicationUser : IdentityUser { public async Task<ClaimsIdentity> GenerateUserIdentityAsync( UserManager<ApplicationUser> manager ) { // Note the authenticationType must match the one defined...

Entity Framework: relate identity 2 user to product model

entity-framework,asp.net-web-api2,asp.net-identity-2
I'm using Web API 2 and Entity Framework 6 and Identity 2 I have product model which relates to an ApplicationUser model, where I create Product, I get an error: Additional information: An entity object cannot be referenced by multiple instances of IEntityChangeTracker. My model: public class Product { public...

Storing hash of username using ASP.NET identity

owin,asp.net-identity-2,asp.net-authorization
I'm writing an application which needs to have personally identifiable information removed/absent at all times from the database. Given that someone may use their real name in their username, and that an email address may be present in their AspUserIdentity records, I have decided one solution might be to hash...

How to show user profile image in asp.net mvc5 layout page?

asp.net-mvc,asp.net-mvc-5,asp.net-identity,identity,asp.net-identity-2
In my application i want to show user profile image in layout page (_LoginPartial).In database their is a student table which has a userid field that is maintain the relationship between AspNetUser table.Student table has the image field.So How to show that image in Layout page (_LoginPartial) view. Thanks

How do I seed IdentityUser references in an Entity Framework application?

asp.net,entity-framework,entity-framework-6,asp.net-identity-2,seeding
I have an Entity Framework application using ASP.NET Identity 2.2 (i.e., my context inherits from IdentityDbContext<T> and I have a User class that inherits from IdentityUser). I am successfully seeding the AspNetUsers table using the following calls in my seed method: var testUser = new User() { UserName = "TestUser",...

Where is the appropriate spot to seed and login a default user with ASP.NET MVC Identity 2.0?

c#,asp.net-mvc,asp.net-mvc-4,startup,asp.net-identity-2
I have an application that uses Identity 2.0 with Owin. I want the application to seed a default user and log in automatically while on development (I'm wrapping the method and its call with #if DEBUG condition). I tried adding the following method to IdentityConfig.csApplicationUserManager.Create method , but after calling...

Getting additional fields with Identity 2.0 in Layout page

c#,asp.net,asp.net-identity-2
I have an issue that I assumed would be a simple fix, but has turned into a big problem. On my _Layout.cshtml page, I just want to display the current user's first and last name. This is stored in the AspNetUsers database table in the Name column. I currently have...

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?...

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...

Generate access token for “auto sign in” links

c#,asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-identity-2
I have a page in my ASP.NET MVC project that users should be able to access just by pressing a link (without signing in). I think I should generate some kind of access token based on the username/userId, but I'm not really sure how. Full authentication (via sign in) should...

how to Use Asp.net Identity with DataBase first approach

c#,entity-framework,webforms,asp.net-identity-2
Hello I am Trying to create Asp.net webforms application with .net 4.5 framework. I have my existing DataBase and I need to work with tha dataBase first approch at the sameTime I need to use ASP.identity. I try to recreate tables which are générated by default with asp.identity In my...

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...

ASP.net Identity 2.0, how to delete user but restrict username from being used again?

asp.net,asp.net-mvc,asp.net-identity,asp.net-identity-2
I have a site using ASP.net identity 2.0 for user management with a few external authentication options as well (google,facebook,etc). I want to give users the option to delete their account. I found a good example of how to implement this in this answer: ASP.NET MVC 5 how to delete...

ApplicationUserManager doesn't use my custom UserStore implementation

asp.net-mvc,asp.net-mvc-5,asp.net-identity,asp.net-identity-2
I created a new MVC5 Application with ASP.NET Identity. I haven't changed lot of the files. This is the error I get: The following changes in the project differ from the VisualStudio template: ApplicationUserManager.cs public class ApplicationUserManager : UserManager<User> { public ApplicationUserManager(IUserStore<User> userStore) : base(userStore) { } public static ApplicationUserManager...

usermanager.findasync returns null for code generated users

asp.net-mvc-5,asp.net-identity-2
I'm having a problem with users that I create in code. They work for the first few login attempts but then after a while stop logging in and return null from the findasync method. if I do a findbyname it returns the user however this doesn't check the password so...

ASP.Net Identity Login Redirect Enforce Protocol (Https)

asp.net-mvc,owin,asp.net-identity-2
Hopefully I'm just missing something really simple/obvious - why, and more importantly, how do you maintain (or force) the protocol during the redirect to Login? To illustrate: the original protocol is https one would think this should be the "default" for something like login, but as shown, the redirect (seems)...

MVC/Code First: how to add more tables to the same db context?

asp.net-mvc,entity-framework,ef-code-first,asp.net-identity,asp.net-identity-2
I am using the standard MVC template that comes with VS 2013. It has a neat membership provider that makes using external logins (Google, Facebook etc) a breeze. There are also tutorials on how to extend the IdentityUser model to add new properties such as date of birth. I would...

List of values as a user attribute

c#,asp.net,asp.net-mvc-4,asp.net-identity-2
I'm using identity 2.1.0 in ASP.NET MVC 5 application, and I have pages for admin to work (create/edit/delete user) with some custom user properties I defined. However I need to store a list of values in one field. How can I achieve this by using identity, and how to show...

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...

Why isn't a claim updated immediately in ASP.NET MVC?

asp.net-mvc,claims-based-identity,asp.net-identity-2
I'm using ASP.NET MVC 5, and ASP.NET Identity. I have extended the default ApplicationUser class like this: public class ApplicationUser : IdentityUser { public string Fullname { get; set; } public byte[] ImageData { get; set; } public string ImageMimeType { get; set; } public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) {...

Get password from a user with UserManager

c#,asp.net-mvc,asp.net-identity-2,usermanager
I'm making a website with MVC5 ASP.NET. I'm using Identity framework 2.0 implement class with properties such as passwordhash, username, email, emailconfirmed and so on. I'm using userManager.ChangePassword(user.Id, Oldpassword, Newpassword);, but i can't figure out how i should get a password from a user as plain text (string) [HttpPost] public...

.NET Identity 2.0 with custom salted passwords

asp.net-identity-2,password-encryption
I'm trying to switch to .NET Identity from an old custom membership provider in an existing MVC application, and maintain dapper as the ORM, not EntityFramework which comes out of the box. I'm stuck at trying to implement my own IPasswordHasher, as I need the existing credentials to work. In...

Web Api 2: Authorising against custom claims

asp.net-web-api,asp.net-identity,asp.net-web-api2,owin,asp.net-identity-2
In certain controllers, I want to authorize a user against a company ID. For example, consider the following resource: api/v1/companies/1234/orders This should only be accessible by users who belong to company 1234. Note that I am using OAuth token bearer authentication. Creating the company claim in OAuthAuthorizationServerProvider: public override async...

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...

Identity API 2.0 Check if user is admin role on View

asp.net-mvc,asp.net-mvc-5,asp.net-identity-2
Inside the scaffolded partial view _Layout.cshtml is defined the app's navigation bar. I'd like to modify it so that some links are only shown if the logged user is "Admin". Inside the Seed() method of my Configuration.cs file for migrations, is defined the following: bool AddUserAndRole(ApplicationDbContext context) { IdentityResult ir;...

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...

Using ASP.NET Identity with my own entities in MVC

c#,asp.net,asp.net-mvc,entity-framework,asp.net-identity-2
In my "Car Hire" solution I have a separate project that holds all my entities such as User,Role, Car, Booking etc. I am using EntityFramework Code First to generate the database. All of that is working fine. I have added a MVC project to my solution. Now I want to...

ASP.NET Identity + Entity Framework + SQLite to share

sqlite,entity-framework-6,c#-5.0,asp.net-identity-2,asp.net-mvc-5.2
For our project needs, I created my own ASP.NET Identity 2.0 Provider with SQLite database, and Entity Framework used in MVC 5.2 application. It's methods are all async. All of the problems with the connection to SQLite DB are resolved (I saw many questions regarding this) So, my question is...

Understanding ASp.net Identity key points

asp.net-mvc-5,entity-framework-6,asp.net-identity-2
I am an Asp.net developer but very much new to the Asp.net Identity framework. I have been studying the sample application and followed some tutorials too on Identity but still I am not able to grasp the concept completely. I have very firm grip over Asp.net membership but Identity seems...

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,...

Two questions about MVC, and Identity

c#,razor,asp.net-mvc-5,asp.net-identity-2
I am very new to identity and MVC, I am trying to create an MVC app as one of my first projects. I have been able to follow a few tutorials and have successfully added additional properties to my ApplicationUser : IdentityUser class public class ApplicationUser : IdentityUser<string, ApplicationUserLogin, ApplicationUserRole,...

ASP.NET Identity “Role-based” Claims

asp.net-identity,asp.net-web-api2,claims-based-identity,asp.net-identity-2,asp.net-authentication
I understand that I can use claims to make statements about a user: var claims = new List<Claim>(); claims.Add(new Claim(ClaimTypes.Name, "Peter")); claims.Add(new Claim(ClaimTypes.Email, "[email protected]")); But how should I store "role-based" claims? For example: The user is a super administrator. claims.Add(new Claim("IsSuperAdmin, "true")); The value parameter "true" feels completely redundant. How...

Using MVC 5's identity, can't get user name right after logging in

asp.net-mvc,asp.net-mvc-5,asp.net-identity-2
I'm trying to use the MVC 5's identity solution, but got stuck on something that should be very simple: I want the login method on the AccountController to get the loged user's name right after validating the model (and I don't want to use it from the model!). Here's a...

Get IdentityUser by ID using MVC 5 Identity

c#,asp.net-mvc,asp.net-mvc-5,asp.net-identity-2
When creating another model Testimonial I store the active user's Id as the Author which is a string looking like: 00b9c6aa-010c-4cbd-ac16-c72d05e7906a. In another view I want to display the name and other user information associated with that Id for each Testimonial. The view will contain information from many different users,...

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 2 Separation of Email and UserName and using Email to login

c#,asp.net,asp.net-mvc,asp.net-mvc-5,asp.net-identity-2
By default, ASP.NET Identity has the UserName and Email fields as being the email the user inputs. I've already changed it so that my system takes in a separate username and email for the user. My problem is that now I cannot login to the system because of the checks...

ASP.NET Identity 2 when saving extended Application User it inserts duplicate data or saving two times

c#,asp.net,webforms,asp.net-identity-2
I added some fields to ApplicationUser like this: public class ApplicationUser : IdentityUser { public virtual UserType Type { get; set; } public string FirstName { get; set; } public string CompanyName { get; set; } } When registering user by this code, it automatically inserts duplicate data - type...

ASP.NET Identity provider based on text file

asp.net,asp.net-identity-2
I am building a simple ASP.NET 5 admin site, using ASP.NET Identity 2 to password protect the actual admin pages. It will be used by 2 to 4 users. My employer doesn't want me to use a database for various reasons beyond my control. The plan is to store all...