6

How do you create a custom ASP.NET MVC 5 Auth without using the UserStore of Microsoft.AspNet.Identity.EntityFramework??

3
  • by using universal providers ? not tested with MVC5, but with MVC4 Commented Aug 25, 2014 at 15:05
  • Do you want to avoid EF? Shoe given you a stub of how you can implement your own UserStore that might not depend on EF. It is a chore to implement though... Commented Aug 25, 2014 at 15:15
  • I find that most people who don't want to use Identity either have very specific requirements, or they don't understand it and think it's too much work (it's absolutely not, it's bone dead simple, it's much more work to implement it yourself) Commented Aug 25, 2014 at 20:21

2 Answers 2

2

All you have to do is implement the same interfaces that the Userstore for Identity.Entityframework uses.

User will be your user class

public class MyUserStore<TUser> : 
    IUserLoginStore<TUser, int>, 
    IUserClaimStore<TUser, int>, 
    IUserRoleStore<TUser, int>, 
    IUserPasswordStore<TUser, int>, 
    IUserSecurityStampStore<TUser, int>, 
    IUserStore<TUser, int>, 
    IDisposable where TUser : User
{
   //Implement the interfaces you need
}

Then pass your MyUserStore into the UserManager each request

new UserManager<User, int>(new MyUserStore<User>(new MyContext()))
Sign up to request clarification or add additional context in comments.

5 Comments

Thats a bit of work.. but thanks.. Is there any other way to make the login/logout simple? Asp.NET MVC 5 Default AccountController seems complex.. I just have a simple user class with username and password stored in the DB..
Are you looking to make it simple or not use Identity.Entityframework? Because that namespace is really meant to do a bunch of the grunt work for you.
Is there any guide out there to customizing these things?
Simple and Dont wanna use the Identity.EntityFramework.. I want to adapt it to my application I already have my DbContexts.. and a DbSet<User> the User class is what I wrote..
There isn't really a way. Either you use the hookups to identity from identity.entityframework or you implement your own hookups. The other option is ditching the usermanager entirely and creating identities manually.
0

You can grab UserStore.cs template from the following project on GitHub and tweak it as you like, it will allow you to get rid of the dependency on Microsoft.AspNet.Identity.EntityFramework.

https://github.com/kriasoft/AspNet-Server-Template -> ./src/App.Server/Data/UserStore.cs

(disclaimer: I'm the author of this project template)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.