asp.net core3.1 实战开发(授权,鉴权封装详解)

本文详细介绍了如何在ASP.NET Core 3.1中进行授权和鉴权的封装,涵盖了实际开发中的关键步骤和最佳实践,帮助开发者理解并实现更安全的Web应用控制。
摘要由CSDN通过智能技术生成

使用方式

#region 设置自己的schema的handler 
            services.AddAuthenticationCore(options => options.AddScheme<MyHandler>("myScheme", "demo myScheme"));
            #endregion

            #region 支持 policy 认证授权的服务  

            // 指定通过策略验证的策略列
            services.AddSingleton<IAuthorizationHandler, AdvancedRequirement>();

            services.AddAuthorization(options =>
            {
   
                //AdvancedRequirement可以理解为一个别名
                options.AddPolicy("AdvancedRequirement", policy =>
                {
   
                    policy.AddRequirements(new NameAuthorizationRequirement("1"));
                });
            }).AddAuthentication(options =>
            {
   
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;
            })
            .AddCookie(options =>
            {
   
                options.LoginPath = new PathString("/Fourth/Login");
                options.ClaimsIssuer = "Cookie";
            });

            #endregion

            #region  Schame 验证

            services.AddAuthentication(options =>
            {
   
                options.DefaultScheme = CookieAuthenticationDefaults.AuthenticationScheme;// "Richard";//  
            })
            .AddCookie(options =>
            {
   
                options.LoginPath = new PathString("/Fourth/Login");// 这里指定如果验证不通过就跳转到这个页面中去
                options.ClaimsIssuer = "Cookie";
            });
            #endregion
#region 认证授权基本模型
 登录
app.Map("/login", builder => builder.Use(next =>
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值