User authentication and authorization in ASP.NET5 (1) _ Practical skills

Source: Internet
Author: User

In recent times, Microsoft has made a big splash, with the IDE releasing a new Visual Studio 2015 Preview In addition to the VIAUSL Studio 2013 Community Edition.

ASP.NET5, the user's authentication and authorization provides a very rich function, if combined with EF7, you can automatically generate the relevant database table, the call is also very convenient.

However, it is really a headache to understand such a large stack of classes about authentication authorization, or to customize the certification authority according to the specific requirements of your project. To solve this problem, there is a fundamental understanding of the mechanism of authentication and authorization, but this is not a simple matter, some concepts are also more abstract, for the sake of understanding, here I use the simplest example to demonstrate how to authenticate and authorize, and without using the EF, without using the database, Simple demo authentication and authorization itself.

To authenticate, first you have to have users, here we build a user class as follows:

<summary>
 ///User
 ///</summary> public
 class HDUser
 {
  ///<summary>
  // /user Id
  ///</summary> public
  string Id {get; set;}
  <summary>
  ///Login
  ///</summary> public
  string UserName {get; set;}
  <summary>
  ///Specification user name
  ///</summary> public
  string Normalizedusername {get; set;}
  <summary>
  ///Password
  ///</summary> public
  string PassWord {get; set;}
  <summary>
  ///Hash encoded password
  ///</summary> public
  string PasswordHash {get; set;}
  <summary>
  ///User's role
  ///</summary> public
  virtual icollection 
 

Here, the fields of the HDUser class are much easier to understand, the normalizedusername difficult to understand some, can be simply considered to be the username of the upper case.

Then the role class:

 <summary>
 ///role
 ///</summary> public
 class Hdrole
 {
  ///<summary>
  // /role ID
  ///</summary> public
  string Id {get; set;}
  <summary>
  ///role name
  ///</summary> public
  string name {get; set;}
 }

With users and roles, the user role class is required to establish a relationship between the user and the role:

<summary>
 ///User Role Correspondence
 ///</summary> public
 class Hduserrole
 {
  ///< summary>
  ///User ID
  ///</summary> public
  virtual string UserId {get; set;}
  <summary>
  ///role ID
  ///</summary> public
  virtual string Roleid {get; set;}
 }

In this way, the three most basic classes we have built up.

Well, the above through a simple example of the ASP.NET5 in the user authentication and authorization (1), the next chapter to continue to introduce ASP.NET5 in the user authentication and authorization (2), the need to click between the friends to see.

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.