詳細なセキュリティクッキーのログイン認証コア

System.Collections.Genericを使用しました。
System.Linqのを使用しました。
System.Security.Claimsを使用しました。
Microsoft.AspNetCore.Builderを使用しました。
Microsoft.AspNetCore.Httpを使用しました。
Microsoft.AspNetCore.Hostingを使用しました。
Microsoft.AspNetCore.Authenticationを使用しました。
Microsoft.AspNetCore.Authentication.Cookiesを使用しました。
Microsoft.Extensions.DependencyInjectionを使用しました。

名前空間CookieSessionSample 
{ 
    publicクラススタートアップ
    { 
        ます。public void ConfigureServices(IServiceCollectionサービス)
        { 
            //これはhttps://github.com/aspnet/IISIntegration/issues/371た後に除去することができます
            services.AddAuthentication(オプション=> 
            {
                = CookieAuthenticationDefaults.AuthenticationScheme options.DefaultAuthenticateScheme; 
                options.DefaultChallengeScheme = CookieAuthenticationDefaults.AuthenticationScheme; 
            })addCookie(= O> = o.SessionStore新しい新しいMemoryCacheTicketStore());. 
        } 

        公共ボイド設定(IApplicationBuilder APP)
        { 
            app.UseAuthentication(); 

            アプリ.RUNは(非同期コンテキスト=> 
            { 
                IF(!context.User.Identities.Any(アイデンティティ=> identity.IsAuthenticated))
                {//通常の認証プロセスは、ここで書かれていません、それは本明細書中では検証は、未登録た
                //一般カスタム・ユーザー・パスワードの認証動作は、ログイン資格情報で構造を確認した後、 
                    //は、大規模なアイデンティティを作ります
                    VaRの主張=新しいリスト<クレーム>(1001); 
                    claims.Add(新しいクレーム(ClaimTypes.Name、 "ボブ")); 
                    以下のために(INT I = 0; I <1000; I ++)
                    { 
                        claims.Add(新しい項(ClaimTypes.Role、 "SomeRandomGroup" + I、ClaimValueTypes.String、 "IssuedByBob"、 "OriginalIssuerJoe")); 
                    } 

                    //写入登录验证方案与凭证到クッキー
                    のawait context.SignInAsync(CookieAuthenticationDefaults.AuthenticationScheme、
                        新しいClaimsPrincipal(新しいClaimsIdentity(特許請求の範囲、CookieAuthenticationDefaults.AuthenticationScheme)))。   

                    context.Response.ContentType = "
                    await context.Response.WriteAsync( "こんにちはファーストタイマー"); 
                    リターン;

                context.Response.ContentType = "text / plainの"; 
                await context.Response.WriteAsync( "こんにちは古いタイマー"); 
            }); 
        } 
    } 
}

おすすめ

転載: www.cnblogs.com/ms_senda/p/12501157.html