c# - ASP.net mvc4 - how to make make user and role anagement -


i create small web page using mvc4, reason not see reason make custom authentication , use implemented , working authenticate. problem default can not manage users , roles browser. reason implement own simple management. problem dont know how acces membership tables via entity framework. when start application, webform authentification creates tables in database. after stop application , create data model entity framework database many errors webform authentification.

so question is: when want access membership data, have use created models or there simple way how can access via entity framework?

it's not simple. first add entity framework using nuget packages console or managment. should create model database, smth like:

 public class user     {         [databasegenerated(databasegeneratedoption.identity)]                 [column(order = 1)]         public long n { get; set; }         [required]         [column(order = 2)]         public string id { get; set; }            public string login { get; set; }             public string password { get; set; }             public int accountrole { get; set; }      } 

next step create database context :

 public class mydbcontext: dbcontext, idisposable t : class {     public dbset<user> users { get; set; }              public mydbcontext() : base("$dbconnectionstring") { }               public new void dispose()     {         base.dispose();                 }       }  

change $dbconnectionstring connection string.

but don't store password plain text string. encrypt it. in controller have manipulate cookies assign them if user has authenticated , recognized 1 of users in users property of mydbcontext. check if accountrole property has value of admin , add portion of cookies. check cookies every time (or other) user trying access secured methods in controller.

p.s. nice use irepository or irepository<t> pattern on compact project such yours.


Comments

Popular posts from this blog

powershell Start-Process exit code -1073741502 when used with Credential from a windows service environment -

twig - Using Twigbridge in a Laravel 5.1 Package -

c# - LINQ join Entities from HashSet's, Join vs Dictionary vs HashSet performance -