Yyt.Abp.Authorize
1.0.4
dotnet add package Yyt.Abp.Authorize --version 1.0.4
NuGet\Install-Package Yyt.Abp.Authorize -Version 1.0.4
<PackageReference Include="Yyt.Abp.Authorize" Version="1.0.4" />
<PackageVersion Include="Yyt.Abp.Authorize" Version="1.0.4" />
<PackageReference Include="Yyt.Abp.Authorize" />
paket add Yyt.Abp.Authorize --version 1.0.4
#r "nuget: Yyt.Abp.Authorize, 1.0.4"
#:package Yyt.Abp.Authorize@1.0.4
#addin nuget:?package=Yyt.Abp.Authorize&version=1.0.4
#tool nuget:?package=Yyt.Abp.Authorize&version=1.0.4
Yyt.Abp.Authorize
English Version
Overview
Yyt.Abp.Authorize is a library that simplifies accessing current session information and implementing rate limiting and duplicate submission prevention in .NET microservice architectures, Version 1.0.3 added support for net8, Version 1.0.4 adds support for .NET 10 and resolves the exception caused by empty string values for int types. Built with a modular architecture, it enables seamless integration into your existing projects. Supported by Patrick.Z, this library streamlines repetitive daily development configurations in .NET applications and takes the heavy lifting off your shoulders.
Why Choose Yyt.Abp.Authorize?
- Minimal Dependencies: Lightweight design with minimal external dependencies, keeps your project lean and efficient.
- Secure by Design: Security is prioritized from the design phase to protect sensitive session data.
- Highly Extensible: Flexible architecture that fits your custom business requirements easily.
- Battle-Tested: Proven stable and reliable through validation in multiple production projects.
Core Notes & Features
Note: This library only provides temporary session forwarding capability. You need to implement custom permission filtering logic based on your actual business requirements.
Currently supported pre-defined session properties:
| Property | Description |
|---|---|
| Token | User token |
| UserId | User identifier |
| UserName | User name |
| RoleName | Role name |
| RealName | Real name |
| IsAdmin | Is administrator |
| Id | Identifier |
| ClientType | Client type |
| TenantId | Tenant identifier |
| ExtendId1 ~ ExtendId10 | Extended identifiers (1-10) |
Code Example
AuthFilter
public class ExtAuthorizeFilter : IAsyncAuthorizationFilter
{
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
var action = context.ActionDescriptor as ControllerActionDescriptor;
if (action == null)
{
return;
}
var authorizeAttribute = action.MethodInfo.GetCustomAttribute<AuthorizeAttribute>();
if (authorizeAttribute != null)
{
// get userinfo from token
// ...
context.HttpContext.Items.Add(ContextKeyName.Token, "xxx");
context.HttpContext.Items.Add(ContextKeyName.UserId, "xxx");
context.HttpContext.Items.Add(ContextKeyName.UserName, "xxx");
// save to db
// ...
}
}
}
Controller
[HttpPost]
[Route("demo/save")]
[Authorize]
[EnableRateLimit] //Optional
public async ActionResult AddData(AddDataInput input)
{
// business
// ...
}
Service
public class DemoService : IDemoService
{
private readonly ICurrentShortUser _user;
public DemoService(ICurrentShortUser user)
{
_user = user;
}
public async Task<ServiceResult<string>> AddAnyData(AddDataInput input)
{
var userId = _user.UserId;
// business
}
}
Chinese Version
概述
Yyt.Abp.Authorize 提供了简化微服务中获取当前会话信息和限流防重复提交功能,Version 1.0.3 增加了对net8的支持, Version 1.0.4 版本增加支持net10并且解决了int类型值为""时异常问题。代码采用了 Module 模块化设计,能无缝集成到项目中。该库由 Patrick.Z 提供支持,简化了 .Net 应用程序中的日常开发配置工作,为您分担繁重的工作。
为什么选择 Yyt.Abp.Authorize?
- 极少依赖:轻量级设计,外部依赖少,保持项目精简高效
- 设计安全:从设计阶段就优先考虑安全性,保护敏感会话数据
- 可扩展定制:灵活的架构易于适应自定义业务需求
- 久经沙场:经过多个生产项目验证,稳定可靠
核心说明与功能
注意:需要结合实际业务逻辑实现权限过滤逻辑,本库只提供会话的临时转发。
目前提供保存会话信息属性如下:
| 属性 | 说明 |
|---|---|
| Token | 用户令牌 |
| UserId | 用户标识 |
| UserName | 用户名 |
| RoleName | 角色名 |
| RealName | 真实姓名 |
| IsAdmin | 是否管理员 |
| Id | 标识ID |
| ClientType | 客户端类型 |
| TenantId | 租户ID |
| ExtendId1 ~ ExtendId10 | 扩展标识 (1-10) |
代码示例
AuthFilter
public class ExtAuthorizeFilter : IAsyncAuthorizationFilter
{
public async Task OnAuthorizationAsync(AuthorizationFilterContext context)
{
var action = context.ActionDescriptor as ControllerActionDescriptor;
if (action == null)
{
return;
}
var authorizeAttribute = action.MethodInfo.GetCustomAttribute<AuthorizeAttribute>();
if (authorizeAttribute != null)
{
// get userinfo from token
// ...
context.HttpContext.Items.Add(ContextKeyName.Token, "xxx");
context.HttpContext.Items.Add(ContextKeyName.UserId, "xxx");
context.HttpContext.Items.Add(ContextKeyName.UserName, "xxx");
// save to db
// ...
}
}
}
Controller
[HttpPost]
[Route("demo/save")]
[Authorize]
[EnableRateLimit] //可选
public async ActionResult AddData(AddDataInput input)
{
// business
// ...
}
Service
public class DemoService : IDemoService
{
private readonly ICurrentShortUser _user;
public DemoService(ICurrentShortUser user)
{
_user = user;
}
public async Task<ServiceResult<string>> AddAnyData(AddDataInput input)
{
var userId = _user.UserId;
// business
}
}
Document Version: v1.0
Created Date: June 2026
Author: Patrick.Z
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net6.0 is compatible. net6.0-android was computed. net6.0-ios was computed. net6.0-maccatalyst was computed. net6.0-macos was computed. net6.0-tvos was computed. net6.0-windows was computed. net7.0 was computed. net7.0-android was computed. net7.0-ios was computed. net7.0-maccatalyst was computed. net7.0-macos was computed. net7.0-tvos was computed. net7.0-windows was computed. net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 was computed. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. net10.0 is compatible. net10.0-android was computed. net10.0-browser was computed. net10.0-ios was computed. net10.0-maccatalyst was computed. net10.0-macos was computed. net10.0-tvos was computed. net10.0-windows was computed. |
-
net10.0
- Volo.Abp.AspNetCore (>= 10.0.0)
- Volo.Abp.Core (>= 10.0.0)
-
net6.0
- Volo.Abp.AspNetCore (>= 6.0.2)
- Volo.Abp.Core (>= 6.0.2)
-
net8.0
- Volo.Abp.AspNetCore (>= 8.0.0)
- Volo.Abp.Core (>= 8.0.0)
NuGet packages
This package is not used by any NuGet packages.
GitHub repositories
This package is not used by any popular GitHub repositories.