Defining controllers and views
We need to add two more controllers to the one automatically scaffolded by Visual Studio, namely, AccountController
, which takes care of user login/logout and registration, and ManagePackageController
, which handles all package-related operations. It is enough to right-click on the Controllers
folder and then select Add | Controller. Then, choose the controller name and select the empty MVC controller to avoid the possibility of Visual Studio scaffolding code you don’t need.
For simplicity, AccountController
just has login and logout methods, so you can log in just with the initial administrator user. However, you can add further action methods that use the UserManager
class to define, update, and delete users. The UserManager
class can be provided through DI, as shown here:
private readonly UserManager<IdentityUser<int>> userManager;
private readonly SignInManager<IdentityUser<int>> signInManager;
public AccountController...