ASP.NET Authentication Without Entity Platform

Can I use a new ASP.NET authentication without using the Entity Framework and use my own methods instead?

I have an MVC project that uses simple ADO.NET to access data. I want to implement an ASP.NET identifier, but I would like to continue to use ADO.NET and stored procedures. Thatโ€™s how I decided to go.

+6
source share
2 answers

I had similar requirements for myself and implemented a clean version of SQL Server for the ASP.NET Identity platform.

I started by creating a sample project (using the entity infrastructure), and then observing the tables created. Then I transferred them to the Visual Studio Sql project.

Further, I used this link to give instructions on which methods should be implemented and which methods interact with the database (note: not all methods on stores do / should). The code is in the link for MySQL, but gave me a good idea of โ€‹โ€‹what to implement, etc.

I still have the code that I wrote for the ASP.Net Identity Framework using Sql. So if I get time on the weekend, I'll see how good it is to turn it on and possibly upload it to github and update the link here.

But at the same time use the link - it also provides a good learning experience.

+5
source

I am using Asp.Net Identity 2.2.1. The way I did this was created by my own user:

public class MyUser : IUser {...} 

Then create your own UserStore: (Implement all the methods necessary for the implemented interfaces, and use these methods to pull / paste the data using your data access. For example, I created another dal class on which I use dapper to access the database , I presented an example of one method in my user repository, but this is the same idea for all the other methods that you implement)

 public class MyUserStore : IUserStore<MyUser>, IUserPasswordStore<MyUser>, IUserLockoutStore<MyUser, string>, IUserEmailStore<MyUser> { public Task<MyUser> FindByNameAsync(string userName) { MyUser muser = dal.FindByUsername(userName); if (muser != null) return Task.FromResult<User>(muser); return Task.FromResult<MyUser>(null); } //... all other methods } 

Then the method on my dal.cs looks something like this:

 public MyUser FindByUsername(string username) { //pull user from the database however you want to based on the username, //in my case here is where I used Dapper to query the db and return the User object with the data on it, but you can do it however you want. return myUser; //object with data on it } 

Then on my UserManager I installed the user repository as follows:

 public UserManager() : base(new MyUserStore()) { //anything else you need on the constructor } 

Note : Not all methods in MyUserStore must access the database because many of them call the FindUser ... methods or the UpdateUser method. For example:

 public Task<int> IncrementAccessFailedCountAsync(MyUser user) { //here I just updated the user object as I know that UpdateAsync() method will be called later. return Task.FromResult<int>(++user.FailedAttempts); } 
+5
source

Source: https://habr.com/ru/post/982316/


All Articles