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)