Introduction to asp.net identity, asp. netidentity

Source: Internet
Author: User

Introduction to asp.net identity, asp. netidentity
Asp. Net Identity design goals

Microsoft introduced membership in asp.net 2.0 to provide authentication and authorization functions for asp.net applications. Membership assumes that the user registers on the website and then logs on to the website with the user name and password. Now this assumption is no longer true. With the rise of social networks on the web, people prefer to use social networks to log on to websites. The development method of programmers has also undergone major changes, and unit testing has become the main focus of development. The membership system does not support social network login and unit testing, and cannot meet the current needs. For this reason, Microsoft has developed Asp. Net Identity with the goal:

Unified identification system

  • It can be used in all development frameworks under asp.net, including ASP. net mvc, Web Forms, Web Pages, Web API, and SignalR.
  • Can be used to build web, phone, store or hybrid applications

User Profile)

Programmers can control the architecture of user information.

Persistent Control

By default, data is stored in a relational database, and the Code First object framework is used for persistence. Because the database architecture is controlled by programmers, you can change the table name and primary key data types. You can also change the data storage mode, such as using SharePoint or NoSQL databases.

Here is a project that uses nhib.pdf instead of the Entity Framework for persistence, https://github.com/nhibernate/nhibernate.aspnet.identity.

Unit tests are available.

You can write unit tests for codes that use Asp. Net Identity.

Role provider

Allow role-based authorization

Declaration-based verification

A user's identity is represented by a set of Claims. The statement expresses the user identity better than the role. The relationship between a user and a role is "Belong" and "not belong". The statement can be used to describe the user in more detail.

Social account logon provider

Allow users to log on with facebook, twitter, and other social accounts, and store user-specific data in their own applications.

Azure Active Directory

Allows you to log on using Azure Active Directory and store user-specific data in your own applications.

OWIN Integration

ASP. NET authentication is based on OWIN middleware. ASP. NET Identity has no dependency on System. Web and is a complete OWIN framework. ASP. NET Identity uses OWIN authentication to generate a cookie through OWIN CookieAuthentication instead of FormsAuthentication.

NuGet package

With the NuGet package, the ASP. NET development team can quickly iterate on new features and bug fixes and release them to developers in a timely manner.

Related packages

Microsoft. AspNet. Identity. CoreCore interfaces that contain ASP. NET Identity
Microsoft. AspNet. Identity. OWINThis function allows you to access ASP. NET Identity to OWIN Identity Authentication. It is used when you need to call OWIN Cookie Authentication to generate a cookie.
Microsoft. AspNet. Identity. EntityFrameworkUse the Entity Framework to save user data to the SQL Server database

Related code in Asp. Net MVC

Select personal user authentication when creating a project mvc project. The project template generates the following code:

Use the CreateAsync method of UserManager <TUser, TKey> In the AccountController. Register Method to Register a user:

// AccountController[HttpPost][AllowAnonymous][ValidateAntiForgeryToken]public async Task<ActionResult> Register(RegisterViewModel model){    if (ModelState.IsValid)    {        var user = new ApplicationUser { UserName = model.Email, Email = model.Email };        var result = await UserManager.CreateAsync(user, model.Password);        if (result.Succeeded)        {            await SignInManager.SignInAsync(user, isPersistent:false, rememberBrowser:false);            return RedirectToAction("Index", "Home");        }        AddErrors(result);    }    return View(model);}

Use the PasswordSignInAsync method of SignInManager <TUser, TKey> In the AccountController. Login method to log on.

[HttpPost] [AllowAnonymous] [ValidateAntiForgeryToken] public async Task <ActionResult> Login (LoginViewModel model, string returnUrl) {if (! ModelState. isValid) {return View (model );} // This is not counted in the number of Logon failures counted for account locking. // to trigger account locking when an incorrect password is entered multiple times, change it to shouldLockout: true var result = awaitSignInManager. PasswordSignInAsync(Model. email, model. password, model. rememberMe, shouldLockout: false); switch (result) {case SignInStatus. success: return RedirectToLocal (returnUrl); case SignInStatus. lockedOut: return View ("Lockout"); case SignInStatus. requiresVerification: return RedirectToAction ("SendCode", new {ReturnUrl = returnUrl, RememberMe = model. rememberMe}); case SignInStatus. failure: default: ModelState. addModelErr Or ("", "invalid logon attempt. "); Return View (model );}}

Address: http://www.asp.net/identity/overview/getting-started/introduction-to-aspnet-identity

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.