ASP.NET Framework中基于自定义策略的授权

编程入门 行业动态 更新时间:2024-10-25 05:15:18
本文介绍了ASP.NET Framework中基于自定义策略的授权的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在将ASP.NET API与.NET Framework 4.7.1结合使用

I'm using ASP.NET API with .NET Framework 4.7.1

我正在寻找基于策略的自定义授权.此文档介绍了针对.NET Core的基于策略的自定义授权,但是如何为.NET框架实现呢?

And I'm looking for custom policy-based authorization. This document described custom policy-based authorization for .NET core, but how could I implement it for .NET framework?

推荐答案

有一个Nuget包,它将基于策略的授权反向移植到.NET Framework 4.

There is a Nuget package that backports the Policy-based authorization to .NET Framework 4.

您可以根据需要使用 Microsoft.Owin.Security.Authorization.Mvc 或 Microsoft.Owin.Security.Authorization.WebApi 包.这两个软件包都将为您带来链接文档中所述的相同功能.

You can use Microsoft.Owin.Security.Authorization.Mvc or Microsoft.Owin.Security.Authorization.WebApi package, depending on what you need. Both packages will bring you the same functionalities described in the document you linked.

例如:

using Owin; using Microsoft.Owin; using Microsoft.Owin.Security.Authorization.Infrastructure; using System.IdentityModel.Claims; [assembly: OwinStartup(typeof(Startup))] namespace Concep.Platform.WebApi.App_Start { public class Startup { public void Configuration(IAppBuilder app) { app.UseAuthorization(options => { options.AddPolicy("AbleToCreateUser", policy => policy.RequireClaim(JwtClaimTypes.Role, "Manager")); }); } } }

来源: vladimirgeorgiev/blog/policy-based-authorization-in-asp-net-4/

更多推荐

ASP.NET Framework中基于自定义策略的授权

本文发布于:2023-11-14 10:29:04,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1586968.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:自定义   策略   ASP   NET   Framework

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!