Thursday, October 5, 2017

ASP.NET Identity, Membership and SimpleMembership Comparison


ASP.NET Membership system is published first. It is introduced with ASP.NET 2.0. in 2005., as a standardized way to enable user authentication in ASP.NET applications, instead of custom solution. After that, we got SimpleMembership in 2008., mainly for use with ASP.NET MVC. And finally, we have ASP.NET Identity.
Since user management problem is important, many developers could not wait for Microsoft to do things on right way and created many third party are many third party solutions, in addition to Microsoft's solutions.
ASP.NET Identity is latest membership technology. Its purpose is to replace previous Membership and SympleMembership systems, so both Membership and SimpleMembership become obsolete now. But, new membership is not backward compatible. ASP.NET identity works only with .Net Framework 4.5 or later. If for some reason you must use .Net Framework 2.0 or 3.5 then you have to stay with old Membership or SimpleMembership systems.
New ASP.NET Identity is released as NuGet package and also included by default in Visual Studio 2013. Publishing in form of NuGet package helps to obtain new versions easier in the future. ASP.NET Identity is located in Microsoft.AspNet.Identity.Core namespace.

Characteristics and problems in old ASP.NET Membership system

There are many problems with old ASP.NET Membership system. But, at time when it's published it was great help, when compared with idea to create complete membership yourself. During the time, programmers noticed its flaws.
First, ASP.NET Membership system is hard to customize. It uses SQL Server database only to store data about users. It has predefined user's information table that will be stored. It is not simple to extend default functionality and add custom user fields, or to move data to other kind of database. Membership database schema is designed for SQL Server only. It is hard to move data to other data sources, especially to non-relational databases.
Second, Sign-In and Sign-Out are implemented based on Forms Authentication, so classic Membership system can't use OWIN. These problems are fixed in new ASP.NET Identity membership which has easier customization of user profiles, simple change the data storage and also it's not depending of IIS.

Traits and problems of ASP.NET SimpleMembership system

SimpleMembership is second implementation, which was introduced with Visual Studio 2010 SP1 and WebMatrix. One advantage of SimpleMembership over classic Membership system is that it's easier to customize user profiles. But, all other problems like using membership system on other kind of databases, using of external membership providers, working with OWIN etc., are still there. Also, SimpleMembership is made primarily for MVC. Web Forms applications still used old ASP.NET Membership system which just increased complex and useless burden on common ASP.NET developer.

ASP.NET Identity new features and advantages

ASP.NET Identity membership is newest approach to make membership system on right way. It solves previous problems and also support newest demands, like external login with existing Facebook, Google, Twitter or Live login. Here are most important advantages of ASP.NET Identity:

  • ASP.NET Identity supports all types of ASP.NET applications like Web Forms, MVC, Web API, SignalR or web pages. No need to learn different methods for MVC and Web Forms. Now one membership system supports all kinds of ASP.NET applications.
  • New ASP.NET Identity system is easy to customize. You can add new fields to user profile in no time.
  • ASP.NET Identity is designed based on interfaces which means highly customizable. If you don't like one part of system, you can replace it with your object.
  • Default implementation uses Entity Framework code first. Since database schema is in your hands, you can easily change table names, primary keys, data types etc.
  • By default, system uses SQL Server database. You can change that and use Oracle, MySQL, SharePoint, NoSql, Windows Azure Active Directory and practically any other database.
  • ASP.NET Identity is highly testable. When MVC is introduced, one of intentions was to enable unit testing in web application. But, SimpleMembership still could not be tested. ASP.NET Identity resolves this problem too, and now all parts of ASP.NET web application, including membership system, are unit testable.
  • Support for Claims and Roles. Old membership systems are supporting Roles to enable better authorization. By using Roles, you can allow or disallow access to different parts of web application. ASP.NET Identity has roles too, but also introduces Claims. In short, Roles are like subset of Claims.
    Claims could contain user roles, but also other information about user like first name, last name, email, user groups etc. Because of that, you can allow or disallow user access on many different criteria, practically whatever makes sense for you (e.g. allow access only to users who have a boss named Jeff). Claims are separate part like everything else in ASP.NET Identity. Authentication, authorization, roles and claims are all separated to support easier replace and customization.

    Logical question is, if Claims are so powerful, why ASP.NET Identity offers both Roles and Claims? Why use Roles? Well, Roles are simpler than Claims and many applications simply don't need all of the Claims power. If you are already familiar with Roles and they can satisfy your requirements, it's OK to use them.
  • Users can login with existing Facebook, Google, Twitter or Microsoft Live logins. Millions of people already have accounts on these services. Many of them don't want to register on one more website and remember yet another user name/password pair. If user is not sure if he wants to try your website or not, it could be decisive reason whether you allow login from social networks or not. It is much faster and easier for users if they could just use some existing account to try your website and see what you offer.
  • ASP.NET Identity supports OWIN, which also means that it doesn't depend of System.Web namespace. 
  • Unlike old Membership which uses Forms Authentication dependable on System.Web namespace, ASP.NET Identity is using OWIN CookieAuthentication to generate login cookie.
Obviously, new websites should use ASP.NET Identity since it provides far more benefits than previous membership systems.

How to implement ASP.NET Identity with new ASP.NET website

It is pretty simple to implement ASP.NET Identity feature by using Visual Studio 2013.
Open Visual Studio and press Ctrl + Shift + N on keyboard to open new project window (or alternatively click File -> New -> Project... on top menu). Select ASP.NET Web Application.
Choose project name and project location, and press OK button. On the next screen, window is divided on two parts. On left side, select type of ASP.NET application, like Web Forms, MVC, Single Page etc. On right side you can select authentication method: 
Click on Change Authentication button to see available options. 
To use ASP.NET Identity, make sure that Individual User Accounts option is selected. First option "No Authentication" obviously means that web application will not need any kind of authentication. Last two options are for using of Azure or Windows Active Directory.








0 comments:

Post a Comment

Twitter Delicious Facebook Digg Stumbleupon Favorites More