Sample code for minimum configuration for user login validation in ASP.

Source: Internet
Author: User
Recent work encountered a demand, need in ASP. NET core to achieve a basic identity authentication, the following this article is mainly about the implementation of ASP. NET core to achieve user login verification of the minimum configuration of relevant information, the need for friends can refer to the following to see together.

Objective

This article mainly introduces to you about the ASP. NET core User login verification of the minimum configuration related content, share out for everyone to reference the study, the following words do not say, come together to see the detailed introduction:

The background is to add temporary login functionality to a project, simply verify that the user is logged in, and the minimum configuration and implementation code required is as follows.

Here's how:

Add the configuration of the authentication in the Startup configureservices () method:


Services. Addauthentication (Options =>{options. Defaultauthenticatescheme = Cookieauthenticationdefaults.authenticationscheme; Options. Defaultchallengescheme = Cookieauthenticationdefaults.authenticationscheme;}). Addcookie ();

Add authentication to the request pipeline in the Startup Configure () method:


App. Useauthentication ();

After verifying through the user name/password in the login program, generate the login Cookie and send it to the client via the following code:


var claimsidentity = new Claimsidentity (new claim[] {new Claim (Claimtypes.name, model. (Email)}, "Basic"), var claimsPrincipal = new ClaimsPrincipal (claimsidentity); await Httpcontext.signinasync ( Cookieauthenticationdefaults.authenticationscheme, ClaimsPrincipal);

Summarize

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.