. NET Core upgrade from 1.1 to 2.0 records (Cookie middleware stepping pits)

Source: Internet
Author: User
Tags httpcontext

The new era of. NET Core 2.0

The most watched. NET Core 2.0 was finally released, and the release time for the DOTNETCONF conference, originally scheduled for 9.19, was much earlier than 1 months, and the official release of. NET Core 2.0/.net Standard 2.0 was a significant milestone in. NET open source cross-platform.

. NET Core 2.0 Sdk:https://www.microsoft.com/net/download/core#/sdk

Visual Studio 15.3:https://www.visualstudio.com/zh-hans/downloads/

Update the target framework in an ASP. NET Core Project

Update NuGet dependencies in an ASP. NET Core Web project

Note: Delete the previous microsoft.* dependency, using Microsoft.AspNetCore.All.

How to use the. NET Core 2.0 Update Cookie Middleware

Note: My side of the current project is a separate use of cookie middleware, not in combination with identity.

1: Add cookie Middleware in configureservices, use custom scheme (pit right here)
Services. Addauthentication (options=> {                options. Defaultchallengescheme = cookieautheninfo.qwcmswebcookieinstance;                Options. Defaultsigninscheme = cookieautheninfo.qwcmswebcookieinstance;                Options. Defaultauthenticatescheme = cookieautheninfo.qwcmswebcookieinstance;            })            . Addcookie (cookieautheninfo.qwcmswebcookieinstance, m =                = {M.loginpath = new pathstring ("/account/login") ;                M.accessdeniedpath = new PathString ("/account/denied");                M.logoutpath = new PathString ("/account/logout");                M.cookie.path = "/";             });
Stepping pit: reported abnormal No Authenticationscheme was specified, and there was No Defaultchallengescheme found.

Special thanks to Zonciu for the help.

2: Using cookie Middleware in Configure
App. Useauthentication ();
Using the Microsoft.AspNetCore.Authentication.AuthenticationHttpContextExtensions New extension method

How to use
Sign in to await Httpcontext.signinasync (Cookieautheninfo.qwcmswebcookieinstance, Userprincipal,      new Authenticationproperties      {          EXPIRESUTC = DateTime.UtcNow.AddHours (+),          ispersistent = True,          Allowrefresh = False      });//exit await Httpcontext.signoutasync (cookieautheninfo.qwcmswebcookieinstance);
Authorizeasync now returns the result for Authorizationresult new extension method How to use
var result = await Httpcontext.authenticateasync ("xxxx"), if (result. Succeeded) {    ...}
Reference

1:[Draft] Auth 2.0 Migration Announcement #1310

2:migrating authentication and Identity to ASP. NET Core 2.0

. NET Core upgrade from 1.1 to 2.0 records (Cookie middleware stepping pits)

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.