Friday, 15 January 2010

asp.net mvc - What is the difference between UserManager created using HttpContext vs DBContext -


What is the difference between the two methods for creating a user-manager?

  var userManager1 = HttpContext .GetOwinContext () GetUserManager & LT; ApplicationUserManager & gt; (); Var userManager2 = New User Manager & lt; ApplicationUser & gt; (New userstore & lt; ApplicationUser & gt; (DBCtext);  

Uses HttpContext.GetOwinContext for both the application UserManager and RoleManager . In addition, AccountController uses the HttpContext.GetOwinContext in the default MVC 5 application template, but when I create a new controller that uses UserManager It uses db ( ApplicationDbContext )

Default AccountController

  Public Application User Manager UserManager {get_userManager {get}. HttpContext.GetOwinContext () GetUserManager & LT; ApplicationUserManager & gt; (); } Private Set {_userManager = value; }} // can be used as a Public Action Rule Index () (see return (UserManager.Users.ToList ()); }  

A new administrator

  private applicationDbContext db = new ApplicationDbContext (); // can be used as the Public Action Rashtult Index () {return View (db.Users.ToList ()); }  

In what method should two methods be used?


No comments:

Post a Comment