Like Membership, it is a (sort of) simple way to implement forms authentication in a .NET application. Identity differs from Membership in that it can be unit tested, allows external providers (such as Facebook and Google), and it works for all .NET technologies.
It is surprisingly easy to configure a new MVC web application for forms authentication using Identity. Simply add an ASP.NET Web Application project and choose MVC with Individual User Accounts. Remember to set the Framework version of the new project to 4.5.1 or you will not have these options.
The resulting project will contain:
- An AccountController class that will handle all authentication and user profile functionality.
- A web.config with a connection string pointing at a yet-to-be-created LocalDB database.
- A set of Account views that handles logging in, registrations, and user profile management.
- An AccountViewModels file that contain view models the Account views use.
- An IdentityModel file that contain classes that derive from the built in Identity classes.
- A Startup.Auth file that contains code to configure authentication on start up.
All of this is nicely integrated with the default views and controllers that the ASP.NET template has included for a standard MVC application. You can run it and start registering and logging in immediately with no additional configuration.
It is important to understand the users and passwords are stored in the LocalDB database referred to in the web.config file. This database is created by ASP.NET when you register the first user. When you want to go to production, you can just script this thing out and move it to a production SQL Server.
If you look at the AccountController code, you'll notice that a Microsoft.AspNet.Identity.UserManager class is called for much of the authentication functionality. The UserManager class almost exclusively offers asynchronous methods. Therefore, you have to follow the rules of calling asynchronous methods when using this class.
If you look at the AccountController code, you'll notice that a Microsoft.AspNet.Identity.UserManager class is called for much of the authentication functionality. The UserManager class almost exclusively offers asynchronous methods. Therefore, you have to follow the rules of calling asynchronous methods when using this class.
No comments:
Post a Comment