@ -0,0 +1,242 @@ |
|||||
|
# ABP Platform 10.2 RC Has Been Released |
||||
|
|
||||
|
We are happy to release [ABP](https://abp.io) version **10.2 RC** (Release Candidate). This blog post introduces the new features and important changes in this new version. |
||||
|
|
||||
|
Try this version and provide feedback for a more stable version of ABP v10.2! Thanks to you in advance. |
||||
|
|
||||
|
## Get Started with the 10.2 RC |
||||
|
|
||||
|
You can check the [Get Started page](https://abp.io/get-started) to see how to get started with ABP. You can either download [ABP Studio](https://abp.io/get-started#abp-studio-tab) (**recommended**, if you prefer a user-friendly GUI application - desktop application) or use the [ABP CLI](https://abp.io/docs/latest/cli). |
||||
|
|
||||
|
By default, ABP Studio uses stable versions to create solutions. Therefore, if you want to create a solution with a preview version, first you need to create a solution and then switch your solution to the preview version from the ABP Studio UI: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
## Migration Guide |
||||
|
|
||||
|
There are a few breaking changes in this version that may affect your application. Please read the migration guide carefully, if you are upgrading from v10.1 or earlier: [ABP Version 10.2 Migration Guide](https://abp.io/docs/10.2/release-info/migration-guides/abp-10-2). |
||||
|
|
||||
|
## What's New with ABP v10.2? |
||||
|
|
||||
|
In this section, I will introduce some major features released in this version. |
||||
|
Here is a brief list of titles explained in the next sections: |
||||
|
|
||||
|
- Multi-Tenant Account Usage: Shared User Accounts |
||||
|
- Prevent Privilege Escalation: Assignment Restrictions for Roles and Permissions |
||||
|
- `ClientResourcePermissionValueProvider` for OAuth/OpenIddict |
||||
|
- Angular: Hybrid Localization Support |
||||
|
- Angular: Extensible Table Row Detail |
||||
|
- Angular: CMS Kit Module Features |
||||
|
- Blazor: Upgrade to Blazorise 2.0 |
||||
|
- Identity: Single Active Token Providers |
||||
|
- TickerQ Package Upgrade to 10.1.1 |
||||
|
- AI Management: MCP (Model Context Protocol) Support |
||||
|
- AI Management: RAG with File Upload |
||||
|
- AI Management: OpenAI-Compatible Chat Endpoint |
||||
|
- File Management: Resource-Based Authorization |
||||
|
|
||||
|
### Multi-Tenant Account Usage: Shared User Accounts |
||||
|
|
||||
|
ABP v10.2 introduces **Shared User Accounts**: a single user account can belong to multiple tenants, and the user can choose or switch the active tenant when signing in. This enables a "one account, multiple tenants" experience — for example, inviting the same email address into multiple tenants. |
||||
|
|
||||
|
When you use Shared User Accounts: |
||||
|
|
||||
|
- Username/email uniqueness becomes **global** (Host + all tenants) |
||||
|
- Users are prompted to select the tenant at login if they belong to multiple tenants |
||||
|
- Users can switch between tenants using the tenant switcher in the user menu |
||||
|
- Tenant administrators can invite existing or new users to join a tenant |
||||
|
|
||||
|
Enable shared accounts by configuring `UserSharingStrategy`: |
||||
|
|
||||
|
```csharp |
||||
|
Configure<AbpMultiTenancyOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = true; |
||||
|
options.UserSharingStrategy = TenantUserSharingStrategy.Shared; |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
> See the [Shared User Accounts](https://abp.io/docs/10.2/modules/account/shared-user-accounts) documentation for details. |
||||
|
|
||||
|
### Prevent Privilege Escalation: Assignment Restrictions for Roles and Permissions |
||||
|
|
||||
|
ABP v10.2 implements a unified **privilege escalation prevention** model to address security vulnerabilities where users could assign themselves or others roles or permissions they do not possess. |
||||
|
|
||||
|
**Role Assignment Restriction:** Users can only assign or remove roles they currently have. Users cannot add new roles to themselves (removal only) and cannot assign or remove roles they do not possess. |
||||
|
|
||||
|
**Permission Grant/Revoke Authorization:** Users can only grant or revoke permissions they currently have. Validation applies to both grant and revoke operations. |
||||
|
|
||||
|
**Incremental Permission Protection:** When updating user or role permissions, permissions the current user does not have are treated as non-editable and are preserved as-is during updates. |
||||
|
|
||||
|
Users with the `admin` role can assign any role and grant/revoke any permission. All validations are enforced on the backend — the UI is not a security boundary. |
||||
|
|
||||
|
> See [#24775](https://github.com/abpframework/abp/pull/24775) for more details. |
||||
|
|
||||
|
### `ClientResourcePermissionValueProvider` for OAuth/OpenIddict |
||||
|
|
||||
|
ABP v10.2 adds **ClientResourcePermissionValueProvider**, extending resource-based authorization to OAuth clients. When using IdentityServer or OpenIddict, clients can now have resource permissions aligned with the standard user and role permission model. |
||||
|
|
||||
|
This allows you to control which OAuth clients can access which resources, providing fine-grained authorization for API consumers. The implementation integrates with ABP's existing resource permission infrastructure. |
||||
|
|
||||
|
> See [#24515](https://github.com/abpframework/abp/pull/24515) for more details. |
||||
|
|
||||
|
### Angular: Hybrid Localization Support |
||||
|
|
||||
|
ABP v10.2 introduces **Hybrid Localization** for Angular applications, combining server-side and client-side localization strategies. This gives you flexibility in how translations are loaded and resolved — you can use server-provided localization, client-side fallbacks, or a mix of both. |
||||
|
|
||||
|
This feature is useful when you want to reduce initial load time, support offline scenarios, or have environment-specific localization behavior. The Angular packages have been updated to support the hybrid approach seamlessly. |
||||
|
|
||||
|
> See the [Hybrid Localization](https://abp.io/docs/10.2/framework/ui/angular/hybrid-localization) documentation and [#24731](https://github.com/abpframework/abp/pull/24731). |
||||
|
|
||||
|
### Angular: Extensible Table Row Detail |
||||
|
|
||||
|
ABP v10.2 adds the **ExtensibleTableRowDetailComponent** for expandable row details in extensible tables. You can now display additional information for each row in a collapsible detail section. |
||||
|
|
||||
|
The feature supports row detail templates via both direct input and content child component. It adds toggle logic and emits `rowDetailToggle` events, making it easy to customize the behavior and appearance of expandable rows in your data tables. |
||||
|
|
||||
|
> See [#24636](https://github.com/abpframework/abp/pull/24636) for more details. |
||||
|
|
||||
|
### Angular: CMS Kit Module Features |
||||
|
|
||||
|
ABP v10.2 brings **CMS Kit features to Angular**, completing the cross-platform UI coverage for the CMS Kit module. The Angular implementation includes: Blogs, Blog Posts, Comments, Menus, Pages, Tags, Global Resources, and CMS Settings. |
||||
|
|
||||
|
Together with the CMS Kit Pro Angular implementation (FAQ, Newsletters, Page Feedbacks, Polls, Url forwarding), ABP now provides full Angular UI coverage for both the open-source CMS Kit and CMS Kit Pro modules. |
||||
|
|
||||
|
> See [#24234](https://github.com/abpframework/abp/pull/24234) for more details. |
||||
|
|
||||
|
### Blazor: Upgrade to Blazorise 2.0 |
||||
|
|
||||
|
ABP v10.2 upgrades the [Blazorise](https://blazorise.com/) library to **version 2.0** for Blazor UI. If you are upgrading your project to v10.2 RC, please ensure that all Blazorise-related packages are updated to v2.0 in your application. |
||||
|
|
||||
|
Blazorise 2.0 includes various improvements and changes. Please refer to the [Blazorise 2.0 Release Notes](https://blazorise.com/news/release-notes/200) and the [ABP Blazorise 2.0 Migration Guide](https://abp.io/docs/10.2/release-info/migration-guides/blazorise-2-0-migration) for upgrade instructions. |
||||
|
|
||||
|
> See [#24906](https://github.com/abpframework/abp/pull/24906) for more details. |
||||
|
|
||||
|
### Identity: Single Active Token Providers |
||||
|
|
||||
|
ABP v10.2 introduces a **single active token** policy for password reset, email confirmation, and change-email flows. Three new token providers are available: `AbpPasswordResetTokenProvider`, `AbpEmailConfirmationTokenProvider`, and `AbpChangeEmailTokenProvider`. |
||||
|
|
||||
|
When a new token is generated, it invalidates any previously issued tokens for that purpose. This improves security by ensuring that only the most recently issued token is valid. Token lifespan can be customized via the respective options classes for each provider. |
||||
|
|
||||
|
> See [#24926](https://github.com/abpframework/abp/pull/24926) for more details. |
||||
|
|
||||
|
### TickerQ Package Upgrade to 10.1.1 |
||||
|
|
||||
|
**If you are using the TickerQ integration packages** (`Volo.Abp.TickerQ`, `Volo.Abp.BackgroundJobs.TickerQ`, or `Volo.Abp.BackgroundWorkers.TickerQ`), you need to apply breaking changes when upgrading to ABP 10.2. TickerQ has been upgraded from 2.5.3 to 10.1.1, which only targets .NET 10.0 and contains several API changes. |
||||
|
|
||||
|
Key changes include: |
||||
|
|
||||
|
- `UseAbpTickerQ` moved from `IApplicationBuilder` to `IHost` — use `context.GetHost().UseAbpTickerQ()` in your module |
||||
|
- Entity types renamed: `TimeTicker` → `TimeTickerEntity`, `CronTicker` → `CronTickerEntity` |
||||
|
- Scheduler and dashboard configuration APIs have changed |
||||
|
- New helpers: `context.GetHost()`, `GetWebApplication()`, `GetEndpointRouteBuilder()` |
||||
|
|
||||
|
> **Important:** Do **not** resolve `IHost` from `context.ServiceProvider.GetRequiredService<IHost>()`. Always use `context.GetHost()`. See the [ABP Version 10.2 Migration Guide](https://abp.io/docs/10.2/release-info/migration-guides/abp-10-2) for the complete list of changes. |
||||
|
|
||||
|
### AI Management: MCP (Model Context Protocol) Support |
||||
|
|
||||
|
_This is a **PRO** feature available for ABP Commercial customers._ |
||||
|
|
||||
|
The [AI Management Module](https://abp.io/docs/10.2/modules/ai-management) now supports [MCP (Model Context Protocol)](https://modelcontextprotocol.io/), enabling AI workspaces to use external MCP servers as tools. MCP allows AI models to interact with external services, databases, APIs, and more through a standardized protocol. |
||||
|
|
||||
|
 |
||||
|
|
||||
|
You can create and manage MCP servers via the AI Management UI. Each MCP server supports one of the following transport types: **Stdio** (runs a local command), **SSE** (Server-Sent Events), or **StreamableHttp**. For HTTP-based transports, you can configure authentication (API Key, Bearer token, or custom headers). Once MCP servers are defined, you can associate them with workspaces. When a workspace has MCP servers associated, the AI model can invoke tools from those servers during chat conversations — tool calls and results are displayed in the chat interface. |
||||
|
|
||||
|
You can test the connection to an MCP server after creating it to verify connectivity and list available tools before use: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
When a workspace has MCP servers associated, the AI model can invoke tools from those servers during chat conversations. Tool calls and results are displayed in the chat interface. |
||||
|
|
||||
|
 |
||||
|
|
||||
|
> See the [AI Management documentation](https://abp.io/docs/10.2/modules/ai-management#mcp-servers) for details. |
||||
|
|
||||
|
### AI Management: RAG with File Upload |
||||
|
|
||||
|
_This is a **PRO** feature available for ABP Commercial customers._ |
||||
|
|
||||
|
The AI Management module supports **RAG (Retrieval-Augmented Generation)** with file upload, which enables workspaces to answer questions based on the content of uploaded documents. When RAG is configured, the AI model searches the uploaded documents for relevant information before generating a response. |
||||
|
|
||||
|
To enable RAG, configure an **embedder** (e.g., OpenAI, Ollama) and a **vector store** (e.g., PgVector) on the workspace: |
||||
|
|
||||
|
| Embedder | Vector Store | |
||||
|
| --- | --- | |
||||
|
|  |  | |
||||
|
|
||||
|
You can then upload documents (PDF, Markdown, or text files, max 10 MB) through the workspace management UI. Uploaded documents are automatically processed — their content is chunked, embedded, and stored in the configured vector store: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
When you ask questions in the chat interface, the AI model uses the uploaded documents as context for accurate, grounded responses. |
||||
|
|
||||
|
> See the [AI Management — RAG with File Upload](https://abp.io/docs/10.2/modules/ai-management#rag-with-file-upload) documentation for configuration details. |
||||
|
|
||||
|
### AI Management: OpenAI-Compatible Chat Endpoint |
||||
|
|
||||
|
_This is a **PRO** feature available for ABP Commercial customers._ |
||||
|
|
||||
|
The AI Management module exposes an **OpenAI-compatible REST API** at the `/v1` path. This allows any application or tool that supports the OpenAI API format — such as [AnythingLLM](https://anythingllm.com/), [Open WebUI](https://openwebui.com/), [Dify](https://dify.ai/), or custom scripts using the OpenAI SDK — to connect directly to your AI Management instance. |
||||
|
|
||||
|
**Example configuration from AnythingLLM**: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
Each AI Management **workspace** appears as a selectable model in the client application. The workspace's configured AI provider handles the actual inference transparently. Available endpoints include `/v1/chat/completions`, `/v1/models`, `/v1/embeddings`, `/v1/files`, and more. All endpoints require authentication via a Bearer token in the `Authorization` header. |
||||
|
|
||||
|
> See the [AI Management — OpenAI-Compatible API](https://abp.io/docs/10.2/modules/ai-management#openai-compatible-api) documentation for usage examples. |
||||
|
|
||||
|
### File Management: Resource-Based Authorization |
||||
|
|
||||
|
_This is a **PRO** feature available for ABP Commercial customers._ |
||||
|
|
||||
|
The **File Management Module** now supports **resource-based authorization**. You can control access to individual files and folders per user, role, or client. Permissions can be granted at the resource level via the UI, and the feature integrates with ABP's resource permission infrastructure. |
||||
|
|
||||
|
 |
||||
|
|
||||
|
This feature is **implemented for all three supported UIs: MVC/Razor Pages, Blazor, and Angular**, providing a consistent experience across your application regardless of the UI framework you use. |
||||
|
|
||||
|
### Other Improvements and Enhancements |
||||
|
|
||||
|
- **Angular signal APIs**: ABP Angular packages migrated to signal queries, output functions, and signal input functions for alignment with Angular 21 ([#24765](https://github.com/abpframework/abp/pull/24765), [#24766](https://github.com/abpframework/abp/pull/24766), [#24777](https://github.com/abpframework/abp/pull/24777)). |
||||
|
- **Angular Vitest**: ABP Angular templates now use Vitest as the default testing framework instead of Karma/Jasmine ([#24725](https://github.com/abpframework/abp/pull/24725)). |
||||
|
- **Ambient auditing**: Programmatic disable/enable of auditing via `IAuditingHelper.DisableAuditing()` and `IsAuditingEnabled()` ([#24718](https://github.com/abpframework/abp/pull/24718)). |
||||
|
- **Complex property auditing**: Entity History and ModifierId now support EF Core complex properties ([#24767](https://github.com/abpframework/abp/pull/24767)). |
||||
|
- **RabbitMQ correlation ID**: Correlation ID support added to RabbitMQ JobQueue for distributed tracing ([#24755](https://github.com/abpframework/abp/pull/24755)). |
||||
|
- **Concurrent config retrieval**: `MvcCachedApplicationConfigurationClient` now fetches configuration and localization concurrently for faster startup ([#24838](https://github.com/abpframework/abp/pull/24838)). |
||||
|
- **Environment localization fallback**: Angular can use `environment.defaultResourceName` when the backend does not provide it ([#24589](https://github.com/abpframework/abp/pull/24589)). |
||||
|
- **JS proxy namespace fix**: Resolved namespace mismatch for multi-segment company names in generated proxies ([#24877](https://github.com/abpframework/abp/pull/24877)). |
||||
|
- **Audit Logging max length**: Entity/property type full names increased to 512 characters to reduce truncation ([#24846](https://github.com/abpframework/abp/pull/24846)). |
||||
|
- **AI guidelines**: Cursor and Copilot AI guideline documents added for ABP development ([#24563](https://github.com/abpframework/abp/pull/24563), [#24593](https://github.com/abpframework/abp/pull/24593)). |
||||
|
|
||||
|
## Community News |
||||
|
|
||||
|
### New ABP Community Articles |
||||
|
|
||||
|
As always, exciting articles have been contributed by the ABP community. I will highlight some of them here: |
||||
|
|
||||
|
- [Enis Necipoğlu](https://abp.io/community/members/enisn) has published 2 new posts: |
||||
|
- [ABP Framework's Hidden Magic: Things That Just Work Without You Knowing](https://abp.io/community/articles/hidden-magic-things-that-just-work-without-you-knowing-vw6osmyt) |
||||
|
- [Implementing Multiple Global Query Filters with Entity Framework Core](https://abp.io/community/articles/implementing-multiple-global-query-filters-with-entity-ugnsmf6i) |
||||
|
- [Suhaib Mousa](https://abp.io/community/members/suhaib-mousa) has published 2 new posts: |
||||
|
- [.NET 11 Preview 1 Highlights: Faster Runtime, Smarter JIT, and AI-Ready Improvements](https://abp.io/community/articles/dotnet-11-preview-1-highlights-hspp3o5x) |
||||
|
- [TOON vs JSON for LLM Prompts in ABP: Token-Efficient Structured Context](https://abp.io/community/articles/toon-vs-json-b4rn2avd) |
||||
|
- [Fahri Gedik](https://abp.io/community/members/fahrigedik) has published 2 new posts: |
||||
|
- [Building a Multi-Agent AI System with A2A, MCP, and ADK in .NET](https://abp.io/community/articles/building-a-multiagent-ai-system-with-a2a-mcp-iefdehyx) |
||||
|
- [Async Chain of Persistence Pattern: Designing for Failure in Event-Driven Systems](https://abp.io/community/articles/async-chain-of-persistence-pattern-wzjuy4gl) |
||||
|
- [Alper Ebiçoğlu](https://abp.io/community/members/alper) has published 2 new posts: |
||||
|
- [NDC London 2026: From a Developer's Perspective and My Personal Notes about AI](https://abp.io/community/articles/ndc-london-2026-a-.net-conf-from-a-developers-perspective-07wp50yl) |
||||
|
- [Which Open-Source PDF Libraries Are Recently Popular? A Data-Driven Look At PDF Topic](https://abp.io/community/articles/which-opensource-pdf-libraries-are-recently-popular-a-g68q78it) |
||||
|
- [Stop Spam and Toxic Users in Your App with AI](https://abp.io/community/articles/stop-spam-and-toxic-users-in-your-app-with-ai-3i0xxh0y) by [Engincan Veske](https://abp.io/community/members/EngincanV) |
||||
|
- [How AI Is Changing Developers](https://abp.io/community/articles/how-ai-is-changing-developers-e8y4a85f) by [Liming Ma](https://abp.io/community/members/maliming) |
||||
|
- [JetBrains State of Developer Ecosystem Report 2025 — Key Insights](https://abp.io/community/articles/jetbrains-state-of-developer-ecosystem-report-2025-key-z0638q5e) by [Tarık Özdemir](https://abp.io/community/members/mtozdemir) |
||||
|
- [Integrating AI into ABP.IO Applications: The Complete Guide to Volo.Abp.AI and AI Management Module](https://abp.io/community/articles/integrating-ai-into-abp.io-applications-the-complete-guide-jc9fbjq0) by [Adnan Ali](https://abp.io/community/members/adnanaldaim) |
||||
|
|
||||
|
Thanks to the ABP Community for all the content they have published. You can also [post your ABP related (text or video) content](https://abp.io/community/posts/create) to the ABP Community. |
||||
|
|
||||
|
## Conclusion |
||||
|
|
||||
|
This version comes with some new features and a lot of enhancements to the existing features. You can see the [Road Map](https://abp.io/docs/10.2/release-info/road-map) documentation to learn about the release schedule and planned features for the next releases. Please try ABP v10.2 RC and provide feedback to help us release a more stable version. |
||||
|
|
||||
|
Thanks for being a part of this community! |
||||
|
After Width: | Height: | Size: 31 KiB |
|
After Width: | Height: | Size: 28 KiB |
|
After Width: | Height: | Size: 458 KiB |
|
After Width: | Height: | Size: 11 KiB |
|
After Width: | Height: | Size: 39 KiB |
|
After Width: | Height: | Size: 8.9 KiB |
|
After Width: | Height: | Size: 22 KiB |
|
After Width: | Height: | Size: 12 KiB |
|
After Width: | Height: | Size: 17 KiB |
|
After Width: | Height: | Size: 56 KiB |
@ -0,0 +1,227 @@ |
|||||
|
# Automate Localhost Access for Expo: A Guide to Dynamic Cloudflare Tunnels & Dev Builds |
||||
|
|
||||
|
Every mobile developer eventually hits the "Localhost Wall." You have built a brilliant API on your machine, and your React Native app works perfectly in the iOS Simulator or Android Emulator. But the moment you pick up a physical device to test real-world performance or camera features, everything breaks. |
||||
|
|
||||
|
### The Problem: Why Your Phone Can’t See localhost |
||||
|
|
||||
|
When you run a backend server on your computer, localhost refers to the "loopback" address and essentially, the computer talking to itself. Your physical iPhone or Android device is a separate node on the network. From its perspective, localhost is itself, not your development machine. Without a direct bridge, your mobile app is shouting into a void, unable to reach the API sitting just inches away on your desk. |
||||
|
|
||||
|
### The Conflict: The Fragility of Local IP Addresses |
||||
|
|
||||
|
The traditional workaround is to find the local IP address of your device and hardcode it into your app. However, this approach has many obstacles that make it difficult to use: |
||||
|
|
||||
|
- **Network Volatility:** Your router might assign you a new IP address tomorrow, forcing you to update your code constantly. |
||||
|
- **The SSL Headache:** Modern mobile operating systems and many OAuth providers (like Google or Auth0) strictly require **HTTPS**. Running a local development server with valid SSL certificates is a notorious configuration nightmare. |
||||
|
- **Broken OAuth flows:** Most authentication providers refuse to redirect to a non-secure `http` address or a random local IP, effectively locking you out of testing login features on a real device. |
||||
|
|
||||
|
### The Solution: Cloudflare Tunnel as a Secure Bridge |
||||
|
|
||||
|
This is where **Cloudflare Tunnel** changes the game. Instead of poking holes in your firewall or wrestling with self-signed certificates, Cloudflare Tunnel creates a secure, outbound-only connection between your local machine and the Cloudflare edge. |
||||
|
|
||||
|
It provides you with a **public, HTTPS-enabled URL** (e.g., `https://random-word.trycloudflare.com`) that automatically points to your local port. To your mobile device, your local backend looks like a standard, secure production API. It bypasses network restrictions, satisfies SSL requirements, and—when paired with a simple automation script—makes "localhost" development on physical devices completely seamless. |
||||
|
|
||||
|
### 1. Architecture Overview |
||||
|
|
||||
|
In order to understand why this setup is so effective, it is better to visualize the data flow. Traditionally, your mobile device would try to ping your laptop directly over Wi-Fi that is often blocked by firewalls or complicated by internal IP routing. |
||||
|
|
||||
|
#### Workflow Summary: The Secure "Middleman" |
||||
|
|
||||
|
The Cloudflare Tunnel acts as a persistent, encrypted bridge between your local environment and the public internet. Here is how the traffic flows in a standard development session: |
||||
|
|
||||
|
1. **The Connector:** You run a small `cloudflared` daemon on your development machine. It establishes an **outbound** connection to Cloudflare’s nearest edge server. Because it is outbound, you don't need to open any ports on your home or office router. |
||||
|
2. **The Public Endpoint:** Cloudflare provides a temporary, unique HTTPS URL (e.g., `https://example-tunnel.trycloudflare.com`). This URL is globally accessible. |
||||
|
3. **The Mobile Request:** Your React Native app that is running on a physical iPhone or Android sends an API request to that HTTPS URL. To the phone, this looks like any other secure production website. |
||||
|
4. **The Local Handoff:** Cloudflare receives the request and "tunnels" it down the active connection to your machine. The `cloudflared` tool then forwards that request to your local backend whether it's running on `.NET` at port `44358`, `Node.js` at `3000`, or `Rails` at `3000`. |
||||
|
5. **The Response:** Your backend processes the request and sends the data back through the same tunnel to the phone. |
||||
|
|
||||
|
By sitting in the middle, Cloudflare handles the **SSL termination** and the **Global Routing**, ensuring your backend is reachable regardless of whether your phone is on the same Wi-Fi as your laptop. |
||||
|
|
||||
|
### 2. Prerequisites |
||||
|
|
||||
|
Before we bridge the gap between your mobile device and your local machine, ensure your development environment is equipped with the following core components. |
||||
|
|
||||
|
To follow this guide, you will need: |
||||
|
|
||||
|
- **Node.js & Package Manager:** A stable version of Node.js (LTS recommended) and either **npm** or **yarn** to manage dependencies and run the automation scripts. |
||||
|
- **Expo CLI:** Ensure you have the latest version of `expo` installed globally or within your project. We will be using this to manage the development server and build the application. |
||||
|
- **Cloudflared CLI:** This is the critical "connector" tool from Cloudflare. You’ll need it installed on your local machine to establish the tunnel. |
||||
|
- *Quick Tip:* You don't need a paid Cloudflare account; the **Quick Tunnels** used in this guide are free and require no login. |
||||
|
- **A Running Backend API:** Your local server (e.g., .NET, Node.js, Django, or Rails) should be active and listening on a specific port (like `44358` or `3000`). |
||||
|
|
||||
|
### 3. Step-by-Step Implementation |
||||
|
|
||||
|
Now, let’s configure the automation that makes this workflow "set it and forget it." |
||||
|
|
||||
|
#### Phase A: Backend Configuration (The OAuth Handshake) |
||||
|
|
||||
|
Modern mobile authentication often relies on **OAuth 2.0** or **OpenID Connect**. For the login flow to succeed, your backend must "trust" the redirect URI sent by the mobile app. ABP applications are an example for such handshake. |
||||
|
|
||||
|
Even though we are using a Cloudflare URL for the API calls, the `auth-session` of Expo typically generates a `localhost` redirect for development. You must update your backend configuration (e.g., `appsettings.json` in a .NET TemplateTwo setup) to allow this: |
||||
|
|
||||
|
**File:** `src/YourProject.DbMigrator/appsettings.json` |
||||
|
|
||||
|
```json |
||||
|
{ |
||||
|
"OpenIddict": { |
||||
|
"Applications": { |
||||
|
"Mobile_App": { |
||||
|
"ClientId": "Mobile_App", |
||||
|
"RootUrl": "exp://localhost:19000" |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
**Note:** By setting the `RootUrl` to `exp://localhost:19000`, you ensure that once the user authenticates via the tunnel's secure page, the mobile OS knows exactly how to hand the token back to your running Expo instance. |
||||
|
|
||||
|
#### Phase B: The "Magic" Script (Automating the Tunnel) |
||||
|
|
||||
|
The primary headache with free Cloudflare Tunnels is that they generate a **random URL** every time you restart the service. Manually copying `https://shiny-new-url.trycloudflare.com` into your frontend code every morning is a productivity killer. |
||||
|
|
||||
|
We solve this with a **Node.js automation script** that launches the tunnel, "listens" to the terminal output to find the new URL, and automatically injects it into your project's configuration. |
||||
|
|
||||
|
**File:** `react-native/scripts/tunnel.js` |
||||
|
|
||||
|
```js |
||||
|
const { spawn } = require('child_process'); |
||||
|
const fs = require('fs'); |
||||
|
const path = require('path'); |
||||
|
|
||||
|
// Target files for automation |
||||
|
const tunnelConfigFile = path.join(__dirname, '..', 'tunnel-config.json'); |
||||
|
const environmentFile = path.join(__dirname, '..', 'Environment.ts'); |
||||
|
|
||||
|
// 1. Launch the Cloudflare Tunnel pointing to your local API port |
||||
|
const cloudflared = spawn('cloudflared', ['tunnel', '--url', 'http://localhost:44358']); |
||||
|
|
||||
|
let domainCaptured = false; |
||||
|
|
||||
|
cloudflared.stdout.on('data', data => { |
||||
|
const output = data.toString(); |
||||
|
console.log(output); // Keep logs visible for debugging |
||||
|
|
||||
|
if (!domainCaptured) { |
||||
|
// 2. Regex to catch the dynamic "trycloudflare" URL |
||||
|
const urlMatch = output.match(/https:\/\/([a-z0-9-]+\.trycloudflare\.com)/); |
||||
|
if (urlMatch) { |
||||
|
const domain = urlMatch[1]; |
||||
|
|
||||
|
// 3. Save to a JSON file for the app to read |
||||
|
fs.writeFileSync(tunnelConfigFile, JSON.stringify({ domain }, null, 2)); |
||||
|
|
||||
|
// 4. Update the fallback value in Environment.ts directly |
||||
|
let envContent = fs.readFileSync(environmentFile, 'utf8'); |
||||
|
envContent = envContent.replace( |
||||
|
/let tunnelDomain = '[^']*'; \/\/ fallback/, |
||||
|
`let tunnelDomain = '${domain}'; // fallback`, |
||||
|
); |
||||
|
fs.writeFileSync(environmentFile, envContent, 'utf8'); |
||||
|
|
||||
|
console.log(`\n✅ Tunnel Synchronized: ${domain}`); |
||||
|
domainCaptured = true; |
||||
|
} |
||||
|
} |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
By capturing the trycloudflare.com domain programmatically, we treat the tunnel like a dynamic environment variable. This ensures that your mobile app, your backend OAuth settings, and your API client stay in perfect sync without a single keystroke from you. |
||||
|
|
||||
|
#### Phase C: Environment Integration |
||||
|
|
||||
|
To make this work within your React Native code, your `Environment.ts` file needs to be "smart" enough to look for the generated config file. We use a `try/catch` block so the app doesn't crash if the tunnel isn't running. |
||||
|
|
||||
|
**File:** `react-native/Environment.ts` |
||||
|
|
||||
|
```tsx |
||||
|
let tunnelDomain = 'your-default-fallback.com'; // fallback |
||||
|
|
||||
|
try { |
||||
|
// Pull the latest domain from the script's output |
||||
|
const tunnelConfig = require('./tunnel-config.json'); |
||||
|
if (tunnelConfig?.domain) { |
||||
|
tunnelDomain = tunnelConfig.domain; |
||||
|
} |
||||
|
} catch (e) { |
||||
|
console.warn('⚠️ No active tunnel config found. Using fallback.'); |
||||
|
} |
||||
|
|
||||
|
const apiUrl = `https://${tunnelDomain}`; |
||||
|
|
||||
|
export const getEnvVars = () => { |
||||
|
return { |
||||
|
apiUrl, |
||||
|
// Other environment variables... |
||||
|
}; |
||||
|
}; |
||||
|
``` |
||||
|
|
||||
|
This setup creates a **"Single Source of Truth."** When you run the script, it updates `tunnel-config.json`, and your app instantly points to the correct secure endpoint. |
||||
|
|
||||
|
### 4. Integration with Expo Development Builds |
||||
|
|
||||
|
While you can technically use the standard **Expo Go** app for basic API testing, professional React Native workflows, especially those involving secure authentication and custom networking, rely on **Expo Development Builds**. |
||||
|
|
||||
|
#### Why Development Builds are Essential for This Workflow |
||||
|
|
||||
|
Standard Expo Go is a "one-size-fits-all" sandbox. However, as your app grows, it needs to behave more like a real, standalone binary. Development Builds are preferred for two main reasons: |
||||
|
|
||||
|
- **Custom URL Schemes:** For OAuth flows (like the one configured in Phase A), your app needs to handle specific deep links (e.g., `myapp://`). Expo Go has its own internal URL handling that can sometimes conflict with complex redirect logic. A Development Build allows you to define your own scheme, ensuring the Cloudflare-tunneled backend knows exactly where to send the user back after login. |
||||
|
- **Native Dependency Control:** If your app uses native modules for secure storage, biometrics, or advanced networking, Expo Go won't support them. A Development Build includes your project's specific native code while still giving you the "hot reloading" developer experience of Expo. |
||||
|
|
||||
|
#### Configuring the Build for Tunnelling |
||||
|
|
||||
|
To ensure your development build is ready for the Cloudflare tunnel, you'll typically use the `expo-dev-client` package. This transforms your app into a powerful developer tool that can switch between different local or tunneled environments on the fly. |
||||
|
|
||||
|
> **Pro Tip:** When you run `npx expo start`, your Development Build will look for the `apiUrl` we configured in `Environment.ts`. Since our script has already injected the Cloudflare URL, the physical device will connect to your local backend through the tunnel the moment the app loads. |
||||
|
|
||||
|
### 5. Execution Workflow |
||||
|
|
||||
|
To get your entire stack synchronized, follow this specific launch order. This ensures the tunnel is active and the configuration files are updated before the React Native app attempts to read them. |
||||
|
|
||||
|
#### Step 1: Start the Backend |
||||
|
|
||||
|
Fire up your API (e.g., `.NET`, `Node`, `Go`). Ensure it is listening on the port defined in your `tunnel.js` (e.g., `44358`). |
||||
|
|
||||
|
#### Step 2: Launch the Tunnel |
||||
|
|
||||
|
In a new terminal, run your automation script. |
||||
|
|
||||
|
Wait for the message: `✅ Tunnel Synchronized`. This confirms `tunnel-config.json` has been updated with the new `trycloudflare.com` domain. |
||||
|
|
||||
|
#### Step 3: Start Expo |
||||
|
|
||||
|
Finally, start your Expo development server: |
||||
|
|
||||
|
```bash |
||||
|
npx expo start |
||||
|
``` |
||||
|
|
||||
|
Open the app on your physical device by scanning the QR code. Your app is now communicating with your local machine over a secure, global HTTPS bridge. |
||||
|
|
||||
|
### 6. Troubleshooting & Best Practices |
||||
|
|
||||
|
Even with automation, networking can be finicky. If your app isn't reaching the API, check these common roadblocks: |
||||
|
|
||||
|
#### Common Pitfalls |
||||
|
|
||||
|
- **Port Mismatches:** Ensure the port in your `tunnel.js` script (e.g., `44358`) exactly matches the port your backend is listening on. If your backend uses HTTPS locally, ensure the tunnel command reflects that (e.g., `https://localhost:port`). |
||||
|
- **Firewall & Ghost Processes:** Sometimes a previous `cloudflared` process hangs in the background. If you can't start a new tunnel, kill existing processes or check if your local firewall is blocking `cloudflared` from making outbound connections. |
||||
|
- **Expired Sessions:** Free "Quick Tunnels" are temporary. If you leave your computer on overnight, the tunnel might disconnect. Simply restart the script to generate a fresh, synced URL. |
||||
|
|
||||
|
#### Security Note |
||||
|
|
||||
|
Cloudflare Tunnels create a **publicly accessible URL**. While the random strings in `trycloudflare.com` provide "security through obscurity," anyone with that link can hit your local API. |
||||
|
|
||||
|
- **Development Data Only:** Never use this setup with production databases or sensitive PII (Personally Identifiable Information). |
||||
|
- **Disable When Idle:** Close the tunnel terminal when you aren't actively developing to shut the "bridge" to your machine. |
||||
|
|
||||
|
### 7. Conclusion & Future-Proofing |
||||
|
|
||||
|
By replacing hardcoded local IPs with a dynamic Cloudflare Tunnel, you’ve transformed a clunky, manual process into a **"Set it and forget it"** workflow. You no longer have to worry about shifting Wi-Fi addresses or SSL certificate errors on physical devices. Your development environment now mirrors the behavior of a production app, providing more accurate testing and faster debugging. |
||||
|
|
||||
|
#### The Road to Production: EAS |
||||
|
|
||||
|
This tunneling strategy is the perfect companion for **EAS (Expo Application Services)**. As you move toward testing internal distributions, you can use these same environment patterns to point your EAS-built binaries to various staging or development endpoints. |
||||
|
|
||||
|
With a secure bridge and an automated config, you are no longer tethered to a simulator. Grab your phone, head to a coffee shop, and keep building—your backend is now globally (and securely) following you. |
||||
@ -0,0 +1,201 @@ |
|||||
|
# Resource-Based Authorization in ABP Framework |
||||
|
|
||||
|
ABP has a built-in permission system that supports role-based access control (RBAC). You define permissions, assign them to roles, and assign roles to users — once a user logs in, they automatically have the corresponding access. This covers the vast majority of real-world scenarios and is simple, straightforward, and easy to maintain. |
||||
|
|
||||
|
However, there is one class of requirements it cannot handle: **different access rights for different instances of the same resource type**. |
||||
|
|
||||
|
Take a bookstore application as an example. You define a `Books.Edit` permission and assign it to an editor role, so every editor can modify every book. But reality is often more nuanced: |
||||
|
|
||||
|
- A specific book should only be editable by its assigned editor |
||||
|
- Certain books are only visible to specific users |
||||
|
- Different users have different levels of access to the same book |
||||
|
|
||||
|
Standard permissions cannot address this, because their granularity is the *permission type*, not a *specific record*. The traditional approach requires designing your own database tables, writing query logic, and building a management UI from scratch — all of which is costly. |
||||
|
|
||||
|
ABP Framework now ships with **Resource-Based Authorization** to solve exactly this problem. The core idea is to bind permissions to specific resource instances rather than just resource types. For example, you can grant a user permission to edit the price of *1984* specifically, while they have no access to any other book. |
||||
|
|
||||
|
More importantly, the entire permission management workflow is handled through a built-in UI dialog — **no custom code needed for the management side**. |
||||
|
|
||||
|
## How It Works |
||||
|
|
||||
|
Each resource instance (e.g. a book) can have its own permission management dialog. Users who hold the `ManagePermissions` permission can open it and grant or revoke access for users, roles, or OAuth clients — all from the UI. |
||||
|
|
||||
|
A **Permissions** action appears in each book's action menu: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
Clicking it opens the resource permission management dialog for that specific book. You can see who currently has access and click **Add permission** to grant more: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
The **Add permission** dialog lets you select a user, role, or OAuth client, then choose which permissions to grant: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
After saving, the new entry appears in the list immediately. |
||||
|
|
||||
|
Each entry in the list also supports **Edit** and **Delete** actions. Clicking **Edit** opens the update dialog where you can adjust the granted permissions: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
Clicking **Delete** shows a confirmation prompt — confirming removes all permissions for that user, role, or OAuth client on this book: |
||||
|
|
||||
|
 |
||||
|
|
||||
|
## Setting It Up |
||||
|
|
||||
|
To get this working, you need to define your resource permissions and wire up the dialog. |
||||
|
|
||||
|
### Defining Resource Permissions |
||||
|
|
||||
|
```csharp |
||||
|
public static class BookStorePermissions |
||||
|
{ |
||||
|
public const string GroupName = "BookStore"; |
||||
|
|
||||
|
public static class Books |
||||
|
{ |
||||
|
public const string Default = GroupName + ".Books"; |
||||
|
public const string ManagePermissions = Default + ".ManagePermissions"; |
||||
|
|
||||
|
public static class Resources |
||||
|
{ |
||||
|
public const string Name = "Acme.BookStore.Books.Book"; |
||||
|
public const string View = Name + ".View"; |
||||
|
public const string Edit = Name + ".Edit"; |
||||
|
public const string Delete = Name + ".Delete"; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
```csharp |
||||
|
public override void Define(IPermissionDefinitionContext context) |
||||
|
{ |
||||
|
var group = context.AddGroup(BookStorePermissions.GroupName); |
||||
|
|
||||
|
var bookPermission = group.AddPermission(BookStorePermissions.Books.Default); |
||||
|
|
||||
|
// Users with this permission can open the resource permission dialog |
||||
|
bookPermission.AddChild(BookStorePermissions.Books.ManagePermissions); |
||||
|
|
||||
|
context.AddResourcePermission( |
||||
|
name: BookStorePermissions.Books.Resources.View, |
||||
|
resourceName: BookStorePermissions.Books.Resources.Name, |
||||
|
managementPermissionName: BookStorePermissions.Books.ManagePermissions |
||||
|
); |
||||
|
|
||||
|
context.AddResourcePermission( |
||||
|
name: BookStorePermissions.Books.Resources.Edit, |
||||
|
resourceName: BookStorePermissions.Books.Resources.Name, |
||||
|
managementPermissionName: BookStorePermissions.Books.ManagePermissions |
||||
|
); |
||||
|
|
||||
|
context.AddResourcePermission( |
||||
|
name: BookStorePermissions.Books.Resources.Delete, |
||||
|
resourceName: BookStorePermissions.Books.Resources.Name, |
||||
|
managementPermissionName: BookStorePermissions.Books.ManagePermissions |
||||
|
); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
The `managementPermissionName` acts as a gate: only users who hold `ManagePermissions` will see the resource permission dialog for a book. |
||||
|
|
||||
|
### Wiring Up the Dialog (MVC) |
||||
|
|
||||
|
Add the required script to your page and open the dialog using `abp.ModalManager`: |
||||
|
|
||||
|
```html |
||||
|
@section scripts |
||||
|
{ |
||||
|
<abp-script src="/Pages/Books/Index.js"/> |
||||
|
<abp-script src="/Pages/AbpPermissionManagement/resource-permission-management-modal.js" /> |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
```javascript |
||||
|
var _permissionsModal = new abp.ModalManager({ |
||||
|
viewUrl: abp.appPath + 'AbpPermissionManagement/ResourcePermissionManagementModal', |
||||
|
modalClass: 'ResourcePermissionManagement' |
||||
|
}); |
||||
|
|
||||
|
function openPermissionsModal(bookId, bookName) { |
||||
|
_permissionsModal.open({ |
||||
|
resourceName: 'Acme.BookStore.Books.Book', |
||||
|
resourceKey: bookId, |
||||
|
resourceDisplayName: bookName |
||||
|
}); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
> For Blazor and Angular applications, ABP provides the equivalent `ResourcePermissionManagementModal` component and `ResourcePermissionManagementComponent`. See the [Permission Management Module](https://abp.io/docs/latest/modules/permission-management) documentation for details. |
||||
|
|
||||
|
## Checking Permissions in Code |
||||
|
|
||||
|
The UI manages the permission assignments; the code enforces them at runtime. In your application service, use `AuthorizationService.CheckAsync` to verify that the current user holds a specific permission on a given resource instance. |
||||
|
|
||||
|
All ABP entities implement `IKeyedObject`, which the framework uses to extract the resource key automatically — so you can pass the entity object directly without building the key manually: |
||||
|
|
||||
|
```csharp |
||||
|
public virtual async Task<BookDto> GetAsync(Guid id) |
||||
|
{ |
||||
|
var book = await _bookRepository.GetAsync(id); |
||||
|
|
||||
|
// Throws AbpAuthorizationException if the current user has no View permission on this book |
||||
|
await AuthorizationService.CheckAsync(book, BookStorePermissions.Books.Resources.View); |
||||
|
|
||||
|
return ObjectMapper.Map<Book, BookDto>(book); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<BookDto> UpdateAsync(Guid id, UpdateBookDto input) |
||||
|
{ |
||||
|
var book = await _bookRepository.GetAsync(id); |
||||
|
|
||||
|
await AuthorizationService.CheckAsync(book, BookStorePermissions.Books.Resources.Edit); |
||||
|
|
||||
|
book.Name = input.Name; |
||||
|
await _bookRepository.UpdateAsync(book); |
||||
|
|
||||
|
return ObjectMapper.Map<Book, BookDto>(book); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
If you want to check a permission without throwing an exception — for example, to conditionally show or hide a button — use `IsGrantedAsync` instead, which returns a `bool`: |
||||
|
|
||||
|
```csharp |
||||
|
var canEdit = await AuthorizationService.IsGrantedAsync(book, BookStorePermissions.Books.Resources.Edit); |
||||
|
``` |
||||
|
|
||||
|
## Don't Forget to Clean Up |
||||
|
|
||||
|
Every resource permission grant is stored as a record in the database. When a book is deleted, those records are not removed automatically — orphaned permission data accumulates over time. |
||||
|
|
||||
|
Make sure to clean up resource permissions whenever a resource is deleted: |
||||
|
|
||||
|
```csharp |
||||
|
public virtual async Task DeleteAsync(Guid id) |
||||
|
{ |
||||
|
await _bookRepository.DeleteAsync(id); |
||||
|
|
||||
|
// Clean up all resource permissions for this book |
||||
|
await _resourcePermissionManager.DeleteAsync( |
||||
|
resourceName: BookStorePermissions.Books.Resources.Name, |
||||
|
resourceKey: id.ToString() |
||||
|
); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## Summary |
||||
|
|
||||
|
Resource-Based Authorization fills the gap between "everyone can do this" and "only specific users can do this on specific resources." In practice, most of the work comes down to two things: |
||||
|
|
||||
|
- Define resource permissions and wire up the built-in UI dialog so administrators can assign access through the interface |
||||
|
- Call `AuthorizationService.CheckAsync` in your application services to enforce those permissions at runtime |
||||
|
|
||||
|
Storing permission grants, rendering the dialog, searching for users, roles, and OAuth clients — ABP handles all of that for you. |
||||
|
|
||||
|
## References |
||||
|
|
||||
|
- [Resource-Based Authorization](https://abp.io/docs/latest/framework/fundamentals/authorization/resource-based-authorization) |
||||
|
- [Authorization](https://abp.io/docs/latest/framework/fundamentals/authorization) |
||||
|
- [Permission Management Module](https://abp.io/docs/latest/modules/permission-management) |
||||
|
After Width: | Height: | Size: 54 KiB |
|
After Width: | Height: | Size: 56 KiB |
|
After Width: | Height: | Size: 108 KiB |
|
After Width: | Height: | Size: 33 KiB |
|
After Width: | Height: | Size: 46 KiB |
|
After Width: | Height: | Size: 76 KiB |
@ -0,0 +1,188 @@ |
|||||
|
# Operation Rate Limiting in ABP Framework |
||||
|
|
||||
|
Almost every user-facing system eventually runs into the same problem: **some operations cannot be allowed to run without limits**. |
||||
|
|
||||
|
Sometimes it's a cost issue — sending an SMS costs money, and generating a report hammers the database. Sometimes it's security — a login endpoint with no attempt limit is an open invitation for brute-force attacks. And sometimes it's a matter of fairness — your paid plan says "up to 100 data exports per month," and you need to actually enforce that. |
||||
|
|
||||
|
What all these cases have in common is that the thing being limited isn't an HTTP request — it's a *business operation*, performed by a specific *who*, doing a specific *what*, against a specific *resource*. |
||||
|
|
||||
|
ASP.NET Core ships with a built-in [rate limiting middleware](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit) that sits in the HTTP pipeline. It's excellent for broad API protection — throttling requests per IP to fend off bots or DDoS traffic. But it only sees HTTP requests. It can tell you how many requests came from an IP address; it cannot tell you: |
||||
|
|
||||
|
- **"How many verification codes has this phone number received today?"** The moment the user switches networks, the counter resets — completely useless |
||||
|
- **"How many reports has this user exported today?"** Switching from mobile to desktop gives them a fresh counter |
||||
|
- **"How many times has someone tried to log in as `alice`?"** An attacker rotating through dozens of IPs will never hit the per-IP limit |
||||
|
|
||||
|
There's another gap: some rate-limiting logic has no corresponding HTTP endpoint at all — it lives inside an application service method called by multiple endpoints, or triggered by a background job. HTTP middleware has no place to hook in. |
||||
|
|
||||
|
Real-world requirements tend to look like this: |
||||
|
|
||||
|
- The same phone number can receive at most 3 verification codes per hour, regardless of which device or IP the request comes from |
||||
|
- Each user can generate at most 2 monthly sales reports per day, because a single report query scans millions of records |
||||
|
- Login attempts are limited to 5 failures per username per 5 minutes, *and* 20 failures per IP per hour — two independent counters, both enforced simultaneously |
||||
|
- Free-tier users get 50 AI calls per month, paid users get 500 — this is a product-defined quota, not a security measure |
||||
|
- Your system integrates with an LLM provider (OpenAI, Azure OpenAI, etc.) where every call has a real dollar cost. Without per-user or per-tenant limits, a single user can exhaust your monthly budget overnight |
||||
|
|
||||
|
The pattern is clear: the identity being throttled is a **business identity** — a user, a phone number, a resource ID — not an IP address. And the action being throttled is a **business operation**, not an HTTP request. |
||||
|
|
||||
|
ABP Framework's **Operation Rate Limiting** module is built for exactly this. It lets you enforce limits directly in your application or domain layer, with full awareness of who is doing what. |
||||
|
|
||||
|
Add the package to your project: |
||||
|
|
||||
|
```bash |
||||
|
abp add-package Volo.Abp.OperationRateLimiting |
||||
|
``` |
||||
|
|
||||
|
> Operation Rate Limiting is available starting from **ABP Framework 10.3**. See the [pull request](https://github.com/abpframework/abp/pull/25024) for details. |
||||
|
|
||||
|
## Defining a Policy |
||||
|
|
||||
|
The model is straightforward: define a named policy in `ConfigureServices`, then call `CheckAsync` wherever you need to enforce it. |
||||
|
|
||||
|
Name your policies after the business action they protect — `"SendSmsCode"`, `"GenerateReport"`, `"CallAI"`. A clear name makes the intent obvious at the call site, and avoids the mystery of something like `"policy1"`. |
||||
|
|
||||
|
```csharp |
||||
|
Configure<AbpOperationRateLimitingOptions>(options => |
||||
|
{ |
||||
|
options.AddPolicy("SendSmsCode", policy => |
||||
|
{ |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1) |
||||
|
.PartitionByParameter(); |
||||
|
}); |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
- `WithFixedWindow` sets the time window and maximum count — here, at most 1 call per minute |
||||
|
- `PartitionByParameter` means each distinct value you pass at call time (such as a phone number) gets its own independent counter |
||||
|
|
||||
|
Then inject `IOperationRateLimitingChecker` and call `CheckAsync` at the top of the method you want to protect: |
||||
|
|
||||
|
```csharp |
||||
|
public class SmsAppService : ApplicationService |
||||
|
{ |
||||
|
private readonly IOperationRateLimitingChecker _rateLimitChecker; |
||||
|
|
||||
|
public SmsAppService(IOperationRateLimitingChecker rateLimitChecker) |
||||
|
{ |
||||
|
_rateLimitChecker = rateLimitChecker; |
||||
|
} |
||||
|
|
||||
|
public async Task SendCodeAsync(string phoneNumber) |
||||
|
{ |
||||
|
await _rateLimitChecker.CheckAsync("SendSmsCode", phoneNumber); |
||||
|
|
||||
|
// Limit not exceeded — proceed with sending the SMS |
||||
|
} |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
`CheckAsync` checks the current usage against the limit and throws `AbpOperationRateLimitingException` (HTTP 429) if the limit is already exceeded. If the check passes, it then increments the counter and proceeds. ABP's exception pipeline catches this automatically and returns a standard error response. Put `CheckAsync` first — the rate limit check is the gate, and everything else only runs if it passes. |
||||
|
|
||||
|
## Choosing a Partition Type |
||||
|
|
||||
|
The partition type controls **how counters are isolated from each other** — it's the most important decision when setting up a policy, because it determines *what dimension you're counting across*. |
||||
|
|
||||
|
Getting this wrong can make your rate limiting completely ineffective. Using `PartitionByClientIp` for SMS verification? An attacker just needs to switch networks. Using `PartitionByCurrentUser` for a login endpoint? There's no current user before login, so the counter has nowhere to land. |
||||
|
|
||||
|
- **`PartitionByParameter`** — uses the value you explicitly pass as the partition key. This is the most flexible option. Pass a phone number, an email address, a resource ID, or any business identifier you have at hand. It's the right choice whenever you know exactly what the "who" is. |
||||
|
- **`PartitionByCurrentUser`** — uses the authenticated user's ID, with no value to pass. Perfect for "each user gets N per day" scenarios where user identity is all you need. |
||||
|
- **`PartitionByClientIp`** — uses the client's IP address. Don't rely on this alone — it's too easy to rotate. Use it as a secondary layer alongside another partition type, as in the login example below. |
||||
|
- **`PartitionByEmail`** and **`PartitionByPhoneNumber`** — designed for pre-authentication flows where the user isn't logged in yet. They prefer the `Parameter` value you explicitly pass, and fall back to the current user's email or phone number if none is provided. |
||||
|
- **`PartitionBy`** — a custom async delegate that can produce any partition key you need. When the built-in options don't fit, you're free to implement whatever logic makes sense: look up a resource's owner in the database, derive a key from the user's subscription tier, partition by tenant — anything that returns a string. |
||||
|
|
||||
|
> The rule of thumb: partition by the identity of whoever's behavior you're trying to limit. |
||||
|
|
||||
|
## Combining Rules in One Policy |
||||
|
|
||||
|
A single rule covers most cases, but sometimes you need to enforce limits across multiple dimensions simultaneously. Login protection is the textbook example: throttling by username alone doesn't stop an attacker from targeting many accounts; throttling by IP alone doesn't stop an attacker with a botnet. You need both, at the same time. |
||||
|
|
||||
|
```csharp |
||||
|
options.AddPolicy("Login", policy => |
||||
|
{ |
||||
|
// Rule 1: at most 5 attempts per username per 5-minute window |
||||
|
policy.AddRule(rule => rule |
||||
|
.WithFixedWindow(TimeSpan.FromMinutes(5), maxCount: 5) |
||||
|
.PartitionByParameter()); |
||||
|
|
||||
|
// Rule 2: at most 20 attempts per IP per hour, counted independently |
||||
|
policy.AddRule(rule => rule |
||||
|
.WithFixedWindow(TimeSpan.FromHours(1), maxCount: 20) |
||||
|
.PartitionByClientIp()); |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
The two counters are completely independent. If `alice` fails 5 times, her account is locked — but other accounts from the same IP are unaffected. If an IP accumulates 20 failures, it's blocked — but `alice` can still be targeted from other IPs until their own counters fill up. |
||||
|
|
||||
|
When multiple rules are present, the module uses a two-phase approach: it checks all rules first, and only increments counters if every rule passes. This prevents a rule from consuming quota on a request that would have been rejected by another rule anyway. |
||||
|
|
||||
|
## Beyond Just Checking |
||||
|
|
||||
|
Not every scenario calls for throwing an exception. `IOperationRateLimitingChecker` provides three additional methods for more nuanced control. |
||||
|
|
||||
|
**`IsAllowedAsync`** performs a read-only check — it returns `true` or `false` without touching any counter. The most common use case is UI pre-checking: when a user opens the "send verification code" page, check the limit first. If they've already hit it, disable the button and show a countdown immediately, rather than making them click and get an error. That's a meaningfully better experience. |
||||
|
|
||||
|
```csharp |
||||
|
var isAllowed = await _rateLimitChecker.IsAllowedAsync("SendSmsCode", phoneNumber); |
||||
|
``` |
||||
|
|
||||
|
**`GetStatusAsync`** also reads without incrementing, but returns richer data: `RemainingCount`, `RetryAfter`, and `CurrentCount`. This is what you need to build quota displays — "You have 2 exports remaining today" or "Please try again in 47 seconds" — which are far friendlier than a raw 429. |
||||
|
|
||||
|
```csharp |
||||
|
var status = await _rateLimitChecker.GetStatusAsync("SendSmsCode", phoneNumber); |
||||
|
// status.RemainingCount, status.RetryAfter, status.IsAllowed ... |
||||
|
``` |
||||
|
|
||||
|
**`ResetAsync`** clears the counter for a given policy and context. Useful in admin panels where support staff can manually unblock a user, or in test environments where you need to reset state between runs. |
||||
|
|
||||
|
```csharp |
||||
|
await _rateLimitChecker.ResetAsync("SendSmsCode", phoneNumber); |
||||
|
``` |
||||
|
|
||||
|
## When the Limit Is Hit |
||||
|
|
||||
|
When `CheckAsync` triggers, it throws `AbpOperationRateLimitingException`, which: |
||||
|
|
||||
|
- Inherits from `BusinessException` and maps to HTTP **429 Too Many Requests** |
||||
|
- Is handled automatically by ABP's exception pipeline |
||||
|
- Carries useful metadata: `RetryAfterSeconds`, `RemainingCount`, `MaxCount`, `CurrentCount` |
||||
|
|
||||
|
By default, the error code sent to the client is a generic one from the module. If you want each operation to produce its own localized message — "Too many verification code requests, please wait before trying again" instead of a generic error — assign a custom error code to the policy: |
||||
|
|
||||
|
```csharp |
||||
|
options.AddPolicy("SendSmsCode", policy => |
||||
|
{ |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1) |
||||
|
.PartitionByParameter() |
||||
|
.WithErrorCode("App:SmsCodeLimit"); |
||||
|
}); |
||||
|
``` |
||||
|
|
||||
|
> For details on mapping error codes to localized messages, see [Exception Handling](https://abp.io/docs/latest/framework/fundamentals/exception-handling) in the ABP docs. |
||||
|
|
||||
|
## Turning It Off in Development |
||||
|
|
||||
|
Rate limiting and local development don't mix well. When you're iterating quickly and calling the same endpoint a dozen times to test something, getting blocked by a 429 every few seconds is genuinely painful. Disable the module in your development environment: |
||||
|
|
||||
|
```csharp |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
var hostEnvironment = context.Services.GetHostingEnvironment(); |
||||
|
|
||||
|
Configure<AbpOperationRateLimitingOptions>(options => |
||||
|
{ |
||||
|
if (hostEnvironment.IsDevelopment()) |
||||
|
{ |
||||
|
options.IsEnabled = false; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
``` |
||||
|
|
||||
|
## Summary |
||||
|
|
||||
|
ABP's Operation Rate Limiting fills the gap that ASP.NET Core's HTTP middleware can't: rate limiting with real awareness of *who* is doing *what*. Define a named policy, pick a time window, a max count, and a partition type. Call `CheckAsync` wherever you need it. Counter storage, distributed locking, and exception handling are all taken care of. |
||||
|
|
||||
|
## References |
||||
|
|
||||
|
- [Operation Rate Limiting](https://abp.io/docs/latest/framework/infrastructure/operation-rate-limiting) |
||||
|
- [ASP.NET Core Rate Limiting Middleware](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit) |
||||
|
- [Exception Handling](https://abp.io/docs/latest/framework/fundamentals/exception-handling) |
||||
|
After Width: | Height: | Size: 126 KiB |
@ -0,0 +1,492 @@ |
|||||
|
````json |
||||
|
//[doc-seo] |
||||
|
{ |
||||
|
"Description": "Learn how to use the Operation Rate Limiting module in ABP Framework to control the frequency of specific operations like SMS sending, login attempts, and resource-intensive tasks." |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
# Operation Rate Limiting |
||||
|
|
||||
|
ABP provides an operation rate limiting system that allows you to control the frequency of specific operations in your application. You may need operation rate limiting for several reasons: |
||||
|
|
||||
|
* Do not allow sending an SMS verification code to the same phone number more than 3 times in an hour. |
||||
|
* Do not allow generating a "monthly sales report" more than 2 times per day for each user (if generating the report is resource-intensive). |
||||
|
* Restrict login attempts per IP address to prevent brute-force attacks. |
||||
|
|
||||
|
> This is not for [ASP.NET Core's built-in rate limiting middleware](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit) which works at the HTTP request pipeline level. This module works at the **application/domain code level** and is called explicitly from your services. See the [Combining with ASP.NET Core Rate Limiting](#combining-with-aspnet-core-rate-limiting) section for a comparison. |
||||
|
|
||||
|
## Installation |
||||
|
|
||||
|
You can open a command-line terminal and type the following command to install the [Volo.Abp.OperationRateLimiting](https://www.nuget.org/packages/Volo.Abp.OperationRateLimiting) package into your project: |
||||
|
|
||||
|
````bash |
||||
|
abp add-package Volo.Abp.OperationRateLimiting |
||||
|
```` |
||||
|
|
||||
|
> If you haven't done it yet, you first need to install the [ABP CLI](../../../cli). |
||||
|
|
||||
|
## Quick Start |
||||
|
|
||||
|
This section shows the basic usage of the operation rate limiting system with a simple example. |
||||
|
|
||||
|
### Defining a Policy |
||||
|
|
||||
|
First, define a rate limiting policy in the `ConfigureServices` method of your [module class](../../architecture/modularity/basics.md): |
||||
|
|
||||
|
````csharp |
||||
|
Configure<AbpOperationRateLimitingOptions>(options => |
||||
|
{ |
||||
|
options.AddPolicy("SendSmsCode", policy => |
||||
|
{ |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1) |
||||
|
.PartitionByParameter(); |
||||
|
}); |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
* `"SendSmsCode"` is a unique name for this policy. |
||||
|
* `WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1)` means at most **1 request per minute**. |
||||
|
* `PartitionByParameter()` means the counter is keyed by the parameter you pass at check time (e.g., a phone number), so different phone numbers have independent counters. |
||||
|
|
||||
|
### Checking the Limit |
||||
|
|
||||
|
Then inject `IOperationRateLimitingChecker` and call `CheckAsync` in your service: |
||||
|
|
||||
|
````csharp |
||||
|
public class SmsAppService : ApplicationService |
||||
|
{ |
||||
|
private readonly IOperationRateLimitingChecker _rateLimitChecker; |
||||
|
|
||||
|
public SmsAppService(IOperationRateLimitingChecker rateLimitChecker) |
||||
|
{ |
||||
|
_rateLimitChecker = rateLimitChecker; |
||||
|
} |
||||
|
|
||||
|
public async Task SendCodeAsync(string phoneNumber) |
||||
|
{ |
||||
|
await _rateLimitChecker.CheckAsync("SendSmsCode", phoneNumber); |
||||
|
|
||||
|
// If we reach here, the limit was not exceeded. |
||||
|
// Send the SMS code... |
||||
|
} |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
* `CheckAsync` increments the counter and throws `AbpOperationRateLimitingException` (HTTP 429) if the limit is exceeded. |
||||
|
* Each phone number has its own counter because we used `PartitionByParameter()`. |
||||
|
* Passing `phoneNumber` directly is a shortcut for `new OperationRateLimitingContext { Parameter = phoneNumber }`. Extension methods are provided for all four methods (`CheckAsync`, `IsAllowedAsync`, `GetStatusAsync`, `ResetAsync`) when you only need to pass a `parameter` string. |
||||
|
|
||||
|
That's the basic usage. The following sections explain each concept in detail. |
||||
|
|
||||
|
## Defining Policies |
||||
|
|
||||
|
Policies are defined using `AbpOperationRateLimitingOptions` in the `ConfigureServices` method of your [module class](../../architecture/modularity/basics.md). Each policy has a unique name, one or more rules, and a partition strategy. |
||||
|
|
||||
|
### Single-Rule Policies |
||||
|
|
||||
|
For simple scenarios, use the `WithFixedWindow` shortcut directly on the policy builder: |
||||
|
|
||||
|
````csharp |
||||
|
options.AddPolicy("SendSmsCode", policy => |
||||
|
{ |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1) |
||||
|
.PartitionByParameter(); |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
### Multi-Rule Policies |
||||
|
|
||||
|
Use `AddRule` to combine multiple rules. All rules are checked together (**AND** logic) — a request is allowed only when **all** rules pass: |
||||
|
|
||||
|
````csharp |
||||
|
options.AddPolicy("Login", policy => |
||||
|
{ |
||||
|
// Rule 1: Max 5 attempts per 5 minutes per username |
||||
|
policy.AddRule(rule => rule |
||||
|
.WithFixedWindow(TimeSpan.FromMinutes(5), maxCount: 5) |
||||
|
.PartitionByParameter()); |
||||
|
|
||||
|
// Rule 2: Max 20 attempts per hour per IP |
||||
|
policy.AddRule(rule => rule |
||||
|
.WithFixedWindow(TimeSpan.FromHours(1), maxCount: 20) |
||||
|
.PartitionByClientIp()); |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
> When multiple rules are present, the module uses a **two-phase check**: it first verifies all rules without incrementing counters, then increments only if all rules pass. This prevents wasted quota when one rule would block the request. |
||||
|
|
||||
|
### Custom Error Code |
||||
|
|
||||
|
By default, the exception uses the error code `Volo.Abp.OperationRateLimiting:010001`. You can override it per policy: |
||||
|
|
||||
|
````csharp |
||||
|
options.AddPolicy("SendSmsCode", policy => |
||||
|
{ |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1) |
||||
|
.PartitionByParameter() |
||||
|
.WithErrorCode("App:SmsCodeLimit"); |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
## Partition Types |
||||
|
|
||||
|
Each rule must specify a **partition type** that determines how requests are grouped. Requests with different partition keys have independent counters. |
||||
|
|
||||
|
### PartitionByParameter |
||||
|
|
||||
|
Uses the `Parameter` value from the context you pass to `CheckAsync`: |
||||
|
|
||||
|
````csharp |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1) |
||||
|
.PartitionByParameter(); |
||||
|
|
||||
|
// Each phone number has its own counter |
||||
|
await checker.CheckAsync("SendSmsCode", |
||||
|
new OperationRateLimitingContext { Parameter = phoneNumber }); |
||||
|
```` |
||||
|
|
||||
|
### PartitionByCurrentUser |
||||
|
|
||||
|
Uses `ICurrentUser.Id` as the partition key. The user must be authenticated: |
||||
|
|
||||
|
````csharp |
||||
|
policy.WithFixedWindow(TimeSpan.FromHours(1), maxCount: 10) |
||||
|
.PartitionByCurrentUser(); |
||||
|
```` |
||||
|
|
||||
|
> If you need to check rate limits for a specific user (e.g., admin checking another user's limit), use `PartitionByParameter()` and pass the user ID as the `Parameter`. |
||||
|
|
||||
|
### PartitionByCurrentTenant |
||||
|
|
||||
|
Uses `ICurrentTenant.Id` as the partition key. Uses `"host"` for the host side when no tenant is active: |
||||
|
|
||||
|
````csharp |
||||
|
policy.WithFixedWindow(TimeSpan.FromHours(1), maxCount: 100) |
||||
|
.PartitionByCurrentTenant(); |
||||
|
```` |
||||
|
|
||||
|
### PartitionByClientIp |
||||
|
|
||||
|
Uses `IWebClientInfoProvider.ClientIpAddress` as the partition key: |
||||
|
|
||||
|
````csharp |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(15), maxCount: 10) |
||||
|
.PartitionByClientIp(); |
||||
|
```` |
||||
|
|
||||
|
> This requires an ASP.NET Core environment. In non-web scenarios, the IP address cannot be determined and an exception will be thrown. Use `PartitionByParameter()` if you need to pass the IP explicitly. |
||||
|
|
||||
|
### PartitionByEmail |
||||
|
|
||||
|
Resolves from `context.Parameter` first, then falls back to `ICurrentUser.Email`: |
||||
|
|
||||
|
````csharp |
||||
|
policy.WithFixedWindow(TimeSpan.FromMinutes(1), maxCount: 1) |
||||
|
.PartitionByEmail(); |
||||
|
|
||||
|
// For unauthenticated users, pass the email explicitly: |
||||
|
await checker.CheckAsync("SendEmailCode", |
||||
|
new OperationRateLimitingContext { Parameter = email }); |
||||
|
```` |
||||
|
|
||||
|
### PartitionByPhoneNumber |
||||
|
|
||||
|
Works the same way as `PartitionByEmail`: resolves from `context.Parameter` first, then falls back to `ICurrentUser.PhoneNumber`. |
||||
|
|
||||
|
### Custom Partition (PartitionBy) |
||||
|
|
||||
|
You can provide a custom async function to generate the partition key. The async signature allows you to perform database queries or other I/O operations: |
||||
|
|
||||
|
````csharp |
||||
|
policy.WithFixedWindow(TimeSpan.FromHours(1), maxCount: 100) |
||||
|
.PartitionBy(ctx => Task.FromResult( |
||||
|
$"{ctx.Parameter}:{ctx.ExtraProperties["DeviceId"]}")); |
||||
|
```` |
||||
|
|
||||
|
## Multi-Tenancy |
||||
|
|
||||
|
By default, partition keys do not include tenant information — for partition types like `PartitionByParameter`, `PartitionByCurrentUser`, `PartitionByClientIp`, etc., counters are shared across tenants unless you call `WithMultiTenancy()`. Note that `PartitionByCurrentTenant()` is inherently per-tenant since the partition key is the tenant ID itself, and `PartitionByClientIp()` is typically kept global since the same IP should share a counter regardless of tenant. |
||||
|
|
||||
|
You can enable tenant isolation for a rule by calling `WithMultiTenancy()`: |
||||
|
|
||||
|
````csharp |
||||
|
policy.AddRule(rule => rule |
||||
|
.WithFixedWindow(TimeSpan.FromHours(1), maxCount: 5) |
||||
|
.WithMultiTenancy() |
||||
|
.PartitionByParameter()); |
||||
|
```` |
||||
|
|
||||
|
When multi-tenancy is enabled, the cache key includes the tenant ID, so each tenant has independent counters: |
||||
|
|
||||
|
* **Global key format:** `orl:{PolicyName}:{RuleKey}:{PartitionKey}` |
||||
|
* **Tenant-isolated key format:** `orl:t:{TenantId}:{PolicyName}:{RuleKey}:{PartitionKey}` |
||||
|
|
||||
|
## Checking the Limit |
||||
|
|
||||
|
Inject `IOperationRateLimitingChecker` to interact with rate limits. It provides four methods: |
||||
|
|
||||
|
### CheckAsync |
||||
|
|
||||
|
The primary method. It checks the rate limit and **increments the counter** if allowed. Throws `AbpOperationRateLimitingException` (HTTP 429) if the limit is exceeded: |
||||
|
|
||||
|
````csharp |
||||
|
await checker.CheckAsync("SendSmsCode", |
||||
|
new OperationRateLimitingContext { Parameter = phoneNumber }); |
||||
|
```` |
||||
|
|
||||
|
### IsAllowedAsync |
||||
|
|
||||
|
A read-only check that returns `true` or `false` **without incrementing** the counter. Useful for UI pre-checks (e.g., disabling a button before the user clicks): |
||||
|
|
||||
|
````csharp |
||||
|
var isAllowed = await checker.IsAllowedAsync("SendSmsCode", |
||||
|
new OperationRateLimitingContext { Parameter = phoneNumber }); |
||||
|
```` |
||||
|
|
||||
|
### GetStatusAsync |
||||
|
|
||||
|
Returns detailed status information **without incrementing** the counter: |
||||
|
|
||||
|
````csharp |
||||
|
var status = await checker.GetStatusAsync("SendSmsCode", |
||||
|
new OperationRateLimitingContext { Parameter = phoneNumber }); |
||||
|
|
||||
|
// status.IsAllowed - whether the next request would be allowed |
||||
|
// status.RemainingCount - how many requests are left in this window |
||||
|
// status.RetryAfter - time until the window resets |
||||
|
// status.MaxCount - maximum allowed count |
||||
|
// status.CurrentCount - current usage count |
||||
|
```` |
||||
|
|
||||
|
### ResetAsync |
||||
|
|
||||
|
Resets the counter for a specific policy and context. This can be useful for administrative operations: |
||||
|
|
||||
|
````csharp |
||||
|
await checker.ResetAsync("SendSmsCode", |
||||
|
new OperationRateLimitingContext { Parameter = phoneNumber }); |
||||
|
```` |
||||
|
|
||||
|
## The Exception |
||||
|
|
||||
|
When a rate limit is exceeded, `CheckAsync` throws `AbpOperationRateLimitingException`. This exception: |
||||
|
|
||||
|
* Extends `BusinessException` and implements `IHasHttpStatusCode` with status code **429** (Too Many Requests). |
||||
|
* Is automatically handled by ABP's exception handling pipeline and serialized into the HTTP response. |
||||
|
|
||||
|
The exception uses one of two error codes depending on the policy type: |
||||
|
|
||||
|
| Error Code | Constant | When Used | |
||||
|
|---|---|---| |
||||
|
| `Volo.Abp.OperationRateLimiting:010001` | `AbpOperationRateLimitingErrorCodes.ExceedLimit` | Regular rate limit exceeded (has a retry-after window) | |
||||
|
| `Volo.Abp.OperationRateLimiting:010002` | `AbpOperationRateLimitingErrorCodes.ExceedLimitPermanently` | Ban policy (`maxCount: 0`, permanently denied) | |
||||
|
|
||||
|
You can override the error code per policy using `WithErrorCode()`. When a custom code is set, it is always used regardless of the policy type. |
||||
|
|
||||
|
The exception includes the following data properties: |
||||
|
|
||||
|
| Key | Type | Description | |
||||
|
|-----|------|-------------| |
||||
|
| `PolicyName` | string | Name of the triggered policy | |
||||
|
| `MaxCount` | int | Maximum allowed count | |
||||
|
| `CurrentCount` | int | Current usage count | |
||||
|
| `RemainingCount` | int | Remaining allowed count | |
||||
|
| `RetryAfterSeconds` | int | Seconds until the window resets (`0` for ban policies) | |
||||
|
| `RetryAfterMinutes` | int | Minutes until the window resets, rounded down (`0` for ban policies) | |
||||
|
| `RetryAfter` | string | Localized retry-after description (e.g., "5 minutes"); absent for ban policies | |
||||
|
| `WindowDurationSeconds` | int | Total window duration in seconds | |
||||
|
| `WindowDescription` | string | Localized window description | |
||||
|
| `RuleDetails` | List | Per-rule details (for multi-rule policies) | |
||||
|
|
||||
|
## Configuration |
||||
|
|
||||
|
### AbpOperationRateLimitingOptions |
||||
|
|
||||
|
`AbpOperationRateLimitingOptions` is the main options class for the operation rate limiting system: |
||||
|
|
||||
|
````csharp |
||||
|
Configure<AbpOperationRateLimitingOptions>(options => |
||||
|
{ |
||||
|
options.IsEnabled = true; |
||||
|
options.LockTimeout = TimeSpan.FromSeconds(5); |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
* **`IsEnabled`** (`bool`, default: `true`): Global switch to enable or disable rate limiting. When set to `false`, all `CheckAsync` calls pass through without checking. This is useful for disabling rate limiting in development (see [below](#disabling-in-development)). |
||||
|
* **`LockTimeout`** (`TimeSpan`, default: `5 seconds`): Timeout for acquiring the distributed lock during counter increment operations. |
||||
|
|
||||
|
## Advanced Usage |
||||
|
|
||||
|
### Disabling in Development |
||||
|
|
||||
|
You may want to disable rate limiting during development to avoid being blocked while testing: |
||||
|
|
||||
|
````csharp |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
var hostEnvironment = context.Services.GetHostingEnvironment(); |
||||
|
|
||||
|
Configure<AbpOperationRateLimitingOptions>(options => |
||||
|
{ |
||||
|
if (hostEnvironment.IsDevelopment()) |
||||
|
{ |
||||
|
options.IsEnabled = false; |
||||
|
} |
||||
|
}); |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
### Ban Policy (maxCount: 0) |
||||
|
|
||||
|
Setting `maxCount` to `0` creates a ban policy that permanently denies all requests regardless of the window duration. The `RetryAfter` value will be `null` since there is no window to wait for. The exception uses the error code `Volo.Abp.OperationRateLimiting:010002` (`AbpOperationRateLimitingErrorCodes.ExceedLimitPermanently`) with the message "Operation rate limit exceeded. This request is permanently denied.": |
||||
|
|
||||
|
````csharp |
||||
|
options.AddPolicy("BlockedUser", policy => |
||||
|
{ |
||||
|
policy.WithFixedWindow(TimeSpan.FromHours(24), maxCount: 0) |
||||
|
.PartitionByParameter(); |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
### Passing Extra Properties |
||||
|
|
||||
|
Use `ExtraProperties` on `OperationRateLimitingContext` to pass additional context data. These values are available in custom partition resolvers and are included in the exception data when the limit is exceeded: |
||||
|
|
||||
|
````csharp |
||||
|
await checker.CheckAsync("ApiCall", new OperationRateLimitingContext |
||||
|
{ |
||||
|
Parameter = apiEndpoint, |
||||
|
ExtraProperties = |
||||
|
{ |
||||
|
["DeviceId"] = deviceId, |
||||
|
["ClientVersion"] = clientVersion |
||||
|
} |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
### Pre-checking Before Expensive Operations |
||||
|
|
||||
|
Use `IsAllowedAsync` or `GetStatusAsync` to check the limit **before** performing expensive work (e.g., validating input or querying the database): |
||||
|
|
||||
|
````csharp |
||||
|
public async Task<SendCodeResultDto> SendCodeAsync(string phoneNumber) |
||||
|
{ |
||||
|
var context = new OperationRateLimitingContext { Parameter = phoneNumber }; |
||||
|
|
||||
|
// Check limit before doing any work |
||||
|
var status = await _rateLimitChecker.GetStatusAsync("SendSmsCode", context); |
||||
|
|
||||
|
if (!status.IsAllowed) |
||||
|
{ |
||||
|
return new SendCodeResultDto |
||||
|
{ |
||||
|
Success = false, |
||||
|
RetryAfterSeconds = (int)(status.RetryAfter?.TotalSeconds ?? 0) |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
// Now do the actual work and increment the counter |
||||
|
await _rateLimitChecker.CheckAsync("SendSmsCode", context); |
||||
|
|
||||
|
await _smsSender.SendAsync(phoneNumber, GenerateCode()); |
||||
|
return new SendCodeResultDto { Success = true }; |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
> `IsAllowedAsync` and `GetStatusAsync` are read-only — they do not increment the counter. Only `CheckAsync` increments. |
||||
|
|
||||
|
### Checking on Behalf of Another User |
||||
|
|
||||
|
`PartitionByCurrentUser()`, `PartitionByCurrentTenant()`, and `PartitionByClientIp()` always resolve from their respective services (`ICurrentUser`, `ICurrentTenant`, `IWebClientInfoProvider`) and do not accept explicit overrides. This design avoids partition key conflicts in [composite policies](#multi-rule-policies) where `Parameter` is shared across all rules. |
||||
|
|
||||
|
If you need to check or enforce rate limits for a **specific user, tenant, or IP**, define the policy with `PartitionByParameter()` and pass the value explicitly: |
||||
|
|
||||
|
````csharp |
||||
|
// Policy definition: use PartitionByParameter for explicit control |
||||
|
options.AddPolicy("UserApiLimit", policy => |
||||
|
{ |
||||
|
policy.WithFixedWindow(TimeSpan.FromHours(1), maxCount: 100) |
||||
|
.PartitionByParameter(); |
||||
|
}); |
||||
|
```` |
||||
|
|
||||
|
````csharp |
||||
|
// Check current user's limit |
||||
|
await checker.CheckAsync("UserApiLimit", |
||||
|
new OperationRateLimitingContext { Parameter = CurrentUser.Id.ToString() }); |
||||
|
|
||||
|
// Admin checking another user's limit |
||||
|
await checker.CheckAsync("UserApiLimit", |
||||
|
new OperationRateLimitingContext { Parameter = targetUserId.ToString() }); |
||||
|
|
||||
|
// Check a specific IP in a background job |
||||
|
await checker.CheckAsync("UserApiLimit", |
||||
|
new OperationRateLimitingContext { Parameter = ipAddress }); |
||||
|
```` |
||||
|
|
||||
|
This approach gives you full flexibility while keeping the API simple — `PartitionByCurrentUser()` is a convenience shortcut for "always use the current authenticated user", and `PartitionByParameter()` is for "I want to specify the value explicitly". |
||||
|
|
||||
|
### Combining with ASP.NET Core Rate Limiting |
||||
|
|
||||
|
This module and ASP.NET Core's built-in [rate limiting middleware](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit) serve different purposes and can be used together: |
||||
|
|
||||
|
| | ASP.NET Core Rate Limiting | Operation Rate Limiting | |
||||
|
|---|---|---| |
||||
|
| **Level** | HTTP request pipeline | Application/domain code | |
||||
|
| **Scope** | All incoming requests | Specific business operations | |
||||
|
| **Usage** | Middleware (automatic) | Explicit `CheckAsync` calls | |
||||
|
| **Typical use** | API throttling, DDoS protection | Business logic limits (SMS, reports) | |
||||
|
|
||||
|
A common pattern is to use ASP.NET Core middleware for broad API protection and this module for fine-grained business operation limits. |
||||
|
|
||||
|
## Extensibility |
||||
|
|
||||
|
### Custom Store |
||||
|
|
||||
|
The default store uses ABP's `IDistributedCache`. You can replace it by implementing `IOperationRateLimitingStore`: |
||||
|
|
||||
|
````csharp |
||||
|
public class MyCustomStore : IOperationRateLimitingStore, ITransientDependency |
||||
|
{ |
||||
|
public Task<OperationRateLimitingStoreResult> IncrementAsync( |
||||
|
string key, TimeSpan duration, int maxCount) |
||||
|
{ |
||||
|
// Your custom implementation (e.g., Redis Lua script for atomicity) |
||||
|
} |
||||
|
|
||||
|
public Task<OperationRateLimitingStoreResult> GetAsync( |
||||
|
string key, TimeSpan duration, int maxCount) |
||||
|
{ |
||||
|
// Read-only check |
||||
|
} |
||||
|
|
||||
|
public Task ResetAsync(string key) |
||||
|
{ |
||||
|
// Reset the counter |
||||
|
} |
||||
|
} |
||||
|
```` |
||||
|
|
||||
|
ABP's [dependency injection](../../fundamentals/dependency-injection.md) system will automatically use your implementation since it replaces the default one. |
||||
|
|
||||
|
### Custom Rule |
||||
|
|
||||
|
You can implement custom rate limiting algorithms (e.g., sliding window, token bucket) by implementing `IOperationRateLimitingRule` and registering it with `AddRule<TRule>()`: |
||||
|
|
||||
|
````csharp |
||||
|
policy.AddRule<MySlidingWindowRule>(); |
||||
|
```` |
||||
|
|
||||
|
### Custom Formatter |
||||
|
|
||||
|
Replace `IOperationRateLimitingFormatter` to customize how time durations are displayed in error messages (e.g., "5 minutes", "2 hours 30 minutes"). |
||||
|
|
||||
|
### Custom Policy Provider |
||||
|
|
||||
|
Replace `IOperationRateLimitingPolicyProvider` to load policies from a database or external configuration source instead of the in-memory options. |
||||
|
|
||||
|
## See Also |
||||
|
|
||||
|
* [ASP.NET Core Rate Limiting Middleware](https://learn.microsoft.com/en-us/aspnet/core/performance/rate-limit) |
||||
|
* [Distributed Caching](../fundamentals/caching.md) |
||||
|
* [Exception Handling](../fundamentals/exception-handling.md) |
||||
|
After Width: | Height: | Size: 24 KiB |
|
After Width: | Height: | Size: 14 KiB |
|
After Width: | Height: | Size: 2.7 KiB |
|
After Width: | Height: | Size: 10 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 45 KiB |
|
After Width: | Height: | Size: 5.5 KiB |
|
After Width: | Height: | Size: 47 KiB |
|
After Width: | Height: | Size: 1.9 KiB |
|
After Width: | Height: | Size: 4.1 KiB |
@ -0,0 +1,22 @@ |
|||||
|
using System; |
||||
|
using System.Reflection; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApiExploring; |
||||
|
|
||||
|
public interface IXmlDocumentationProvider |
||||
|
{ |
||||
|
Task<string?> GetSummaryAsync(Type type); |
||||
|
|
||||
|
Task<string?> GetRemarksAsync(Type type); |
||||
|
|
||||
|
Task<string?> GetSummaryAsync(MethodInfo method); |
||||
|
|
||||
|
Task<string?> GetRemarksAsync(MethodInfo method); |
||||
|
|
||||
|
Task<string?> GetReturnsAsync(MethodInfo method); |
||||
|
|
||||
|
Task<string?> GetParameterSummaryAsync(MethodInfo method, string parameterName); |
||||
|
|
||||
|
Task<string?> GetSummaryAsync(PropertyInfo property); |
||||
|
} |
||||
@ -0,0 +1,231 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Concurrent; |
||||
|
using System.IO; |
||||
|
using System.Linq; |
||||
|
using System.Reflection; |
||||
|
using System.Text.RegularExpressions; |
||||
|
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
|
using System.Xml.Linq; |
||||
|
using System.Xml.XPath; |
||||
|
using Microsoft.Extensions.Logging; |
||||
|
using Microsoft.Extensions.Logging.Abstractions; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.AspNetCore.Mvc.ApiExploring; |
||||
|
|
||||
|
public class XmlDocumentationProvider : IXmlDocumentationProvider, ISingletonDependency |
||||
|
{ |
||||
|
public ILogger<XmlDocumentationProvider> Logger { get; set; } |
||||
|
|
||||
|
public XmlDocumentationProvider() |
||||
|
{ |
||||
|
Logger = NullLogger<XmlDocumentationProvider>.Instance; |
||||
|
} |
||||
|
|
||||
|
private static readonly Regex WhitespaceRegex = new(@"\s+", RegexOptions.Compiled); |
||||
|
|
||||
|
// Matches any remaining XML tags like <c>, <code>, <para>, <b>, etc.
|
||||
|
private static readonly Regex XmlTagRegex = new(@"<[^>]+>", RegexOptions.Compiled); |
||||
|
|
||||
|
// Matches <see cref="T:Foo.Bar"/>, <see langword="null"/>, <paramref name="x"/>, <typeparamref name="T"/>
|
||||
|
private static readonly Regex XmlRefTagRegex = new( |
||||
|
@"<(see|paramref|typeparamref)\s+(cref|name|langword)=""([TMFPE]:)?(?<display>[^""]+)""\s*/?>", |
||||
|
RegexOptions.Compiled); |
||||
|
|
||||
|
private readonly ConcurrentDictionary<Assembly, Lazy<Task<XDocument?>>> _xmlDocCache = new(); |
||||
|
|
||||
|
public virtual async Task<string?> GetSummaryAsync(Type type) |
||||
|
{ |
||||
|
var memberName = GetMemberNameForType(type); |
||||
|
return await GetDocumentationElementAsync(type.Assembly, memberName, "summary"); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<string?> GetRemarksAsync(Type type) |
||||
|
{ |
||||
|
var memberName = GetMemberNameForType(type); |
||||
|
return await GetDocumentationElementAsync(type.Assembly, memberName, "remarks"); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<string?> GetSummaryAsync(MethodInfo method) |
||||
|
{ |
||||
|
var memberName = GetMemberNameForMethod(method); |
||||
|
return await GetDocumentationElementAsync(method.DeclaringType!.Assembly, memberName, "summary"); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<string?> GetRemarksAsync(MethodInfo method) |
||||
|
{ |
||||
|
var memberName = GetMemberNameForMethod(method); |
||||
|
return await GetDocumentationElementAsync(method.DeclaringType!.Assembly, memberName, "remarks"); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<string?> GetReturnsAsync(MethodInfo method) |
||||
|
{ |
||||
|
var memberName = GetMemberNameForMethod(method); |
||||
|
return await GetDocumentationElementAsync(method.DeclaringType!.Assembly, memberName, "returns"); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<string?> GetParameterSummaryAsync(MethodInfo method, string parameterName) |
||||
|
{ |
||||
|
var memberName = GetMemberNameForMethod(method); |
||||
|
var doc = await LoadXmlDocumentationAsync(method.DeclaringType!.Assembly); |
||||
|
if (doc == null) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
var memberNode = doc.XPathSelectElement($"//member[@name='{memberName}']"); |
||||
|
var paramNode = memberNode?.XPathSelectElement($"param[@name='{parameterName}']"); |
||||
|
return CleanXmlText(paramNode); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<string?> GetSummaryAsync(PropertyInfo property) |
||||
|
{ |
||||
|
var memberName = GetMemberNameForProperty(property); |
||||
|
return await GetDocumentationElementAsync(property.DeclaringType!.Assembly, memberName, "summary"); |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<string?> GetDocumentationElementAsync(Assembly assembly, string memberName, string elementName) |
||||
|
{ |
||||
|
var doc = await LoadXmlDocumentationAsync(assembly); |
||||
|
if (doc == null) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
var memberNode = doc.XPathSelectElement($"//member[@name='{memberName}']"); |
||||
|
var element = memberNode?.Element(elementName); |
||||
|
return CleanXmlText(element); |
||||
|
} |
||||
|
|
||||
|
protected virtual Task<XDocument?> LoadXmlDocumentationAsync(Assembly assembly) |
||||
|
{ |
||||
|
return _xmlDocCache.GetOrAdd( |
||||
|
assembly, |
||||
|
asm => new Lazy<Task<XDocument?>>( |
||||
|
() => LoadXmlDocumentationFromDiskAsync(asm), |
||||
|
LazyThreadSafetyMode.ExecutionAndPublication) |
||||
|
).Value; |
||||
|
} |
||||
|
|
||||
|
protected virtual async Task<XDocument?> LoadXmlDocumentationFromDiskAsync(Assembly assembly) |
||||
|
{ |
||||
|
if (string.IsNullOrEmpty(assembly.Location)) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
var xmlFilePath = Path.ChangeExtension(assembly.Location, ".xml"); |
||||
|
if (!File.Exists(xmlFilePath)) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
try |
||||
|
{ |
||||
|
await using var stream = new FileStream(xmlFilePath, FileMode.Open, FileAccess.Read, FileShare.Read, 4096, useAsync: true); |
||||
|
return await XDocument.LoadAsync(stream, LoadOptions.None, CancellationToken.None); |
||||
|
} |
||||
|
catch (Exception ex) |
||||
|
{ |
||||
|
Logger.LogWarning(ex, "Failed to load XML documentation from {XmlFilePath}.", xmlFilePath); |
||||
|
return null; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
private static string? CleanXmlText(XElement? element) |
||||
|
{ |
||||
|
if (element == null) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
// Convert to string first so we can process inline XML tags like <see cref="..."/>
|
||||
|
var raw = element.ToString(); |
||||
|
|
||||
|
// Strip the outer element tags (e.g. <summary>...</summary>)
|
||||
|
var start = raw.IndexOf('>') + 1; |
||||
|
var end = raw.LastIndexOf('<'); |
||||
|
if (start >= end) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
var inner = raw[start..end]; |
||||
|
|
||||
|
// Replace <see cref="T:Foo.Bar"/> with the short name "Bar"
|
||||
|
// Replace <see langword="null"/> with "null"
|
||||
|
// Replace <paramref name="x"/> and <typeparamref name="T"/> with the name
|
||||
|
inner = XmlRefTagRegex.Replace(inner, m => |
||||
|
{ |
||||
|
var display = m.Groups["display"].Value; |
||||
|
// For cref values like "T:Foo.Bar.Baz", return only "Baz"
|
||||
|
var dot = display.LastIndexOf('.'); |
||||
|
return dot >= 0 ? display[(dot + 1)..] : display; |
||||
|
}); |
||||
|
|
||||
|
// Strip any remaining XML tags (e.g. <c>, <code>, <para>, <b>, etc.)
|
||||
|
inner = XmlTagRegex.Replace(inner, string.Empty); |
||||
|
|
||||
|
if (string.IsNullOrWhiteSpace(inner)) |
||||
|
{ |
||||
|
return null; |
||||
|
} |
||||
|
|
||||
|
return WhitespaceRegex.Replace(inner.Trim(), " "); |
||||
|
} |
||||
|
|
||||
|
private static string GetMemberNameForType(Type type) |
||||
|
{ |
||||
|
return $"T:{GetTypeFullName(type)}"; |
||||
|
} |
||||
|
|
||||
|
private static string GetMemberNameForMethod(MethodInfo method) |
||||
|
{ |
||||
|
var typeName = GetTypeFullName(method.DeclaringType!); |
||||
|
var parameters = method.GetParameters(); |
||||
|
if (parameters.Length == 0) |
||||
|
{ |
||||
|
return $"M:{typeName}.{method.Name}"; |
||||
|
} |
||||
|
|
||||
|
var paramTypes = string.Join(",", |
||||
|
parameters.Select(p => GetParameterTypeName(p.ParameterType))); |
||||
|
return $"M:{typeName}.{method.Name}({paramTypes})"; |
||||
|
} |
||||
|
|
||||
|
private static string GetMemberNameForProperty(PropertyInfo property) |
||||
|
{ |
||||
|
var typeName = GetTypeFullName(property.DeclaringType!); |
||||
|
return $"P:{typeName}.{property.Name}"; |
||||
|
} |
||||
|
|
||||
|
private static string GetTypeFullName(Type type) |
||||
|
{ |
||||
|
return type.FullName?.Replace('+', '.') ?? type.Name; |
||||
|
} |
||||
|
|
||||
|
private static string GetParameterTypeName(Type type) |
||||
|
{ |
||||
|
if (type.IsGenericType) |
||||
|
{ |
||||
|
var genericDef = type.GetGenericTypeDefinition(); |
||||
|
var defName = genericDef.FullName!; |
||||
|
defName = defName[..defName.IndexOf('`')]; |
||||
|
var args = string.Join(",", type.GetGenericArguments().Select(GetParameterTypeName)); |
||||
|
return $"{defName}{{{args}}}"; |
||||
|
} |
||||
|
|
||||
|
if (type.IsArray) |
||||
|
{ |
||||
|
return GetParameterTypeName(type.GetElementType()!) + "[]"; |
||||
|
} |
||||
|
|
||||
|
if (type.IsByRef) |
||||
|
{ |
||||
|
return GetParameterTypeName(type.GetElementType()!) + "@"; |
||||
|
} |
||||
|
|
||||
|
return type.FullName ?? type.Name; |
||||
|
} |
||||
|
} |
||||
@ -1,6 +1,8 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.Abp.Http.Modeling; |
namespace Volo.Abp.Http.Modeling; |
||||
|
|
||||
public interface IApiDescriptionModelProvider |
public interface IApiDescriptionModelProvider |
||||
{ |
{ |
||||
ApplicationApiDescriptionModel CreateApiModel(ApplicationApiDescriptionModelRequestDto input); |
Task<ApplicationApiDescriptionModel> CreateApiModelAsync(ApplicationApiDescriptionModelRequestDto input); |
||||
} |
} |
||||
|
|||||
@ -1,6 +1,8 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.Abp.Http.ProxyScripting; |
namespace Volo.Abp.Http.ProxyScripting; |
||||
|
|
||||
public interface IProxyScriptManager |
public interface IProxyScriptManager |
||||
{ |
{ |
||||
string GetScript(ProxyScriptingModel scriptingModel); |
Task<string> GetScriptAsync(ProxyScriptingModel scriptingModel); |
||||
} |
} |
||||
|
|||||
@ -1,10 +1,9 @@ |
|||||
using System; |
using System; |
||||
|
using System.Threading.Tasks; |
||||
|
|
||||
namespace Volo.Abp.Http.ProxyScripting; |
namespace Volo.Abp.Http.ProxyScripting; |
||||
|
|
||||
public interface IProxyScriptManagerCache |
public interface IProxyScriptManagerCache |
||||
{ |
{ |
||||
string GetOrAdd(string key, Func<string> factory); |
Task<string> GetOrAddAsync(string key, Func<Task<string>> factory); |
||||
|
|
||||
void Set(string key, string value); |
|
||||
} |
} |
||||
|
|||||
@ -1,26 +1,31 @@ |
|||||
using System; |
using System; |
||||
using System.Collections.Concurrent; |
using System.Collections.Concurrent; |
||||
using System.Collections.Generic; |
using System.Threading; |
||||
|
using System.Threading.Tasks; |
||||
using Volo.Abp.DependencyInjection; |
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
namespace Volo.Abp.Http.ProxyScripting; |
namespace Volo.Abp.Http.ProxyScripting; |
||||
|
|
||||
public class ProxyScriptManagerCache : IProxyScriptManagerCache, ISingletonDependency |
public class ProxyScriptManagerCache : IProxyScriptManagerCache, ISingletonDependency |
||||
{ |
{ |
||||
private readonly ConcurrentDictionary<string, string> _cache; |
private readonly ConcurrentDictionary<string, string> _cache = new(); |
||||
|
private readonly ConcurrentDictionary<string, Lazy<Task<string>>> _asyncCache = new(); |
||||
|
|
||||
public ProxyScriptManagerCache() |
public async Task<string> GetOrAddAsync(string key, Func<Task<string>> factory) |
||||
{ |
{ |
||||
_cache = new ConcurrentDictionary<string, string>(); |
if (_cache.TryGetValue(key, out var cached)) |
||||
} |
{ |
||||
|
return cached; |
||||
|
} |
||||
|
|
||||
public string GetOrAdd(string key, Func<string> factory) |
var result = await _asyncCache.GetOrAdd( |
||||
{ |
key, |
||||
return _cache.GetOrAdd(key, factory); |
_ => new Lazy<Task<string>>(factory, LazyThreadSafetyMode.ExecutionAndPublication) |
||||
} |
).Value; |
||||
|
|
||||
public void Set(string key, string value) |
_cache[key] = result; |
||||
{ |
_asyncCache.TryRemove(key, out _); |
||||
_cache[key] = value; |
|
||||
|
return result; |
||||
} |
} |
||||
} |
} |
||||
|
|||||
@ -0,0 +1,3 @@ |
|||||
|
<Weavers xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="FodyWeavers.xsd"> |
||||
|
<ConfigureAwait ContinueOnCapturedContext="false" /> |
||||
|
</Weavers> |
||||
@ -0,0 +1,32 @@ |
|||||
|
<Project Sdk="Microsoft.NET.Sdk"> |
||||
|
|
||||
|
<Import Project="..\..\..\configureawait.props" /> |
||||
|
<Import Project="..\..\..\common.props" /> |
||||
|
|
||||
|
<PropertyGroup> |
||||
|
<TargetFrameworks>netstandard2.0;netstandard2.1;net8.0;net9.0;net10.0</TargetFrameworks> |
||||
|
<Nullable>enable</Nullable> |
||||
|
<WarningsAsErrors>Nullable</WarningsAsErrors> |
||||
|
<AssemblyName>Volo.Abp.OperationRateLimiting</AssemblyName> |
||||
|
<PackageId>Volo.Abp.OperationRateLimiting</PackageId> |
||||
|
<AssetTargetFallback>$(AssetTargetFallback);portable-net45+win8+wp8+wpa81;</AssetTargetFallback> |
||||
|
<GenerateAssemblyConfigurationAttribute>false</GenerateAssemblyConfigurationAttribute> |
||||
|
<GenerateAssemblyCompanyAttribute>false</GenerateAssemblyCompanyAttribute> |
||||
|
<GenerateAssemblyProductAttribute>false</GenerateAssemblyProductAttribute> |
||||
|
<RootNamespace /> |
||||
|
</PropertyGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<None Remove="Volo\Abp\OperationRateLimiting\Localization\*.json" /> |
||||
|
<EmbeddedResource Include="Volo\Abp\OperationRateLimiting\Localization\*.json" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
<ItemGroup> |
||||
|
<ProjectReference Include="..\Volo.Abp.AspNetCore.Abstractions\Volo.Abp.AspNetCore.Abstractions.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.Caching\Volo.Abp.Caching.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.DistributedLocking.Abstractions\Volo.Abp.DistributedLocking.Abstractions.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.Localization\Volo.Abp.Localization.csproj" /> |
||||
|
<ProjectReference Include="..\Volo.Abp.Security\Volo.Abp.Security.csproj" /> |
||||
|
</ItemGroup> |
||||
|
|
||||
|
</Project> |
||||
@ -0,0 +1,14 @@ |
|||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public static class AbpOperationRateLimitingErrorCodes |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Default error code for rate limit exceeded (with a retry-after window).
|
||||
|
/// </summary>
|
||||
|
public const string ExceedLimit = "Volo.Abp.OperationRateLimiting:010001"; |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Error code for ban policy (maxCount: 0) where requests are permanently denied.
|
||||
|
/// </summary>
|
||||
|
public const string ExceedLimitPermanently = "Volo.Abp.OperationRateLimiting:010002"; |
||||
|
} |
||||
@ -0,0 +1,42 @@ |
|||||
|
using Volo.Abp.AspNetCore; |
||||
|
using Volo.Abp.Caching; |
||||
|
using Volo.Abp.DistributedLocking; |
||||
|
using Volo.Abp.Localization; |
||||
|
using Volo.Abp.Localization.ExceptionHandling; |
||||
|
using Volo.Abp.Modularity; |
||||
|
using Volo.Abp.Security; |
||||
|
using Volo.Abp.VirtualFileSystem; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
[DependsOn( |
||||
|
typeof(AbpCachingModule), |
||||
|
typeof(AbpLocalizationModule), |
||||
|
typeof(AbpSecurityModule), |
||||
|
typeof(AbpAspNetCoreAbstractionsModule), |
||||
|
typeof(AbpDistributedLockingAbstractionsModule) |
||||
|
)] |
||||
|
public class AbpOperationRateLimitingModule : AbpModule |
||||
|
{ |
||||
|
public override void ConfigureServices(ServiceConfigurationContext context) |
||||
|
{ |
||||
|
Configure<AbpVirtualFileSystemOptions>(options => |
||||
|
{ |
||||
|
options.FileSets.AddEmbedded<AbpOperationRateLimitingModule>(); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.Resources |
||||
|
.Add<AbpOperationRateLimitingResource>("en") |
||||
|
.AddVirtualJson("/Volo/Abp/OperationRateLimiting/Localization"); |
||||
|
}); |
||||
|
|
||||
|
Configure<AbpExceptionLocalizationOptions>(options => |
||||
|
{ |
||||
|
options.MapCodeNamespace( |
||||
|
"Volo.Abp.OperationRateLimiting", |
||||
|
typeof(AbpOperationRateLimitingResource)); |
||||
|
}); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public class AbpOperationRateLimitingOptions |
||||
|
{ |
||||
|
public bool IsEnabled { get; set; } = true; |
||||
|
|
||||
|
public TimeSpan LockTimeout { get; set; } = TimeSpan.FromSeconds(5); |
||||
|
|
||||
|
public Dictionary<string, OperationRateLimitingPolicy> Policies { get; } = new(); |
||||
|
|
||||
|
public void AddPolicy(string name, Action<OperationRateLimitingPolicyBuilder> configure) |
||||
|
{ |
||||
|
var builder = new OperationRateLimitingPolicyBuilder(name); |
||||
|
configure(builder); |
||||
|
Policies[name] = builder.Build(); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
using Volo.Abp.Localization; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
[LocalizationResourceName("AbpOperationRateLimiting")] |
||||
|
public class AbpOperationRateLimitingResource |
||||
|
{ |
||||
|
} |
||||
@ -0,0 +1,14 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public interface IOperationRateLimitingChecker |
||||
|
{ |
||||
|
Task CheckAsync(string policyName, OperationRateLimitingContext? context = null); |
||||
|
|
||||
|
Task<bool> IsAllowedAsync(string policyName, OperationRateLimitingContext? context = null); |
||||
|
|
||||
|
Task<OperationRateLimitingResult> GetStatusAsync(string policyName, OperationRateLimitingContext? context = null); |
||||
|
|
||||
|
Task ResetAsync(string policyName, OperationRateLimitingContext? context = null); |
||||
|
} |
||||
@ -0,0 +1,277 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using System.Linq; |
||||
|
using System.Threading.Tasks; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
using Microsoft.Extensions.Options; |
||||
|
using Volo.Abp.AspNetCore.WebClientInfo; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
using Volo.Abp.MultiTenancy; |
||||
|
using Volo.Abp.Users; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public class OperationRateLimitingChecker : IOperationRateLimitingChecker, ITransientDependency |
||||
|
{ |
||||
|
protected AbpOperationRateLimitingOptions Options { get; } |
||||
|
protected IOperationRateLimitingPolicyProvider PolicyProvider { get; } |
||||
|
protected IServiceProvider ServiceProvider { get; } |
||||
|
protected IOperationRateLimitingStore Store { get; } |
||||
|
protected ICurrentUser CurrentUser { get; } |
||||
|
protected ICurrentTenant CurrentTenant { get; } |
||||
|
protected IWebClientInfoProvider WebClientInfoProvider { get; } |
||||
|
|
||||
|
public OperationRateLimitingChecker( |
||||
|
IOptions<AbpOperationRateLimitingOptions> options, |
||||
|
IOperationRateLimitingPolicyProvider policyProvider, |
||||
|
IServiceProvider serviceProvider, |
||||
|
IOperationRateLimitingStore store, |
||||
|
ICurrentUser currentUser, |
||||
|
ICurrentTenant currentTenant, |
||||
|
IWebClientInfoProvider webClientInfoProvider) |
||||
|
{ |
||||
|
Options = options.Value; |
||||
|
PolicyProvider = policyProvider; |
||||
|
ServiceProvider = serviceProvider; |
||||
|
Store = store; |
||||
|
CurrentUser = currentUser; |
||||
|
CurrentTenant = currentTenant; |
||||
|
WebClientInfoProvider = webClientInfoProvider; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task CheckAsync(string policyName, OperationRateLimitingContext? context = null) |
||||
|
{ |
||||
|
if (!Options.IsEnabled) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
context = EnsureContext(context); |
||||
|
var policy = await PolicyProvider.GetAsync(policyName); |
||||
|
var rules = CreateRules(policy); |
||||
|
|
||||
|
// Phase 1: Check ALL rules without incrementing to get complete status.
|
||||
|
// Do not exit early: a later rule may have a larger RetryAfter that the caller needs to know about.
|
||||
|
var checkResults = new List<OperationRateLimitingRuleResult>(); |
||||
|
foreach (var rule in rules) |
||||
|
{ |
||||
|
checkResults.Add(await rule.CheckAsync(context)); |
||||
|
} |
||||
|
|
||||
|
if (checkResults.Any(r => !r.IsAllowed)) |
||||
|
{ |
||||
|
// Throw without incrementing any counter; RetryAfter is the max across all blocking rules.
|
||||
|
var aggregatedResult = AggregateResults(checkResults, policy); |
||||
|
ThrowRateLimitException(policy, aggregatedResult, context); |
||||
|
} |
||||
|
|
||||
|
// Phase 2: All rules passed in Phase 1 - now increment counters.
|
||||
|
// Guard against concurrent races where another request consumed the last quota
|
||||
|
// between Phase 1 and Phase 2.
|
||||
|
// Once any rule fails during increment, stop incrementing subsequent rules
|
||||
|
// to minimize wasted quota. Remaining rules use read-only check instead.
|
||||
|
var incrementResults = new List<OperationRateLimitingRuleResult>(); |
||||
|
var phase2Failed = false; |
||||
|
foreach (var rule in rules) |
||||
|
{ |
||||
|
if (phase2Failed) |
||||
|
{ |
||||
|
incrementResults.Add(await rule.CheckAsync(context)); |
||||
|
} |
||||
|
else |
||||
|
{ |
||||
|
var result = await rule.AcquireAsync(context); |
||||
|
incrementResults.Add(result); |
||||
|
if (!result.IsAllowed) |
||||
|
{ |
||||
|
phase2Failed = true; |
||||
|
} |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
if (phase2Failed) |
||||
|
{ |
||||
|
var aggregatedResult = AggregateResults(incrementResults, policy); |
||||
|
ThrowRateLimitException(policy, aggregatedResult, context); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<bool> IsAllowedAsync(string policyName, OperationRateLimitingContext? context = null) |
||||
|
{ |
||||
|
if (!Options.IsEnabled) |
||||
|
{ |
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
context = EnsureContext(context); |
||||
|
var policy = await PolicyProvider.GetAsync(policyName); |
||||
|
var rules = CreateRules(policy); |
||||
|
|
||||
|
foreach (var rule in rules) |
||||
|
{ |
||||
|
var result = await rule.CheckAsync(context); |
||||
|
if (!result.IsAllowed) |
||||
|
{ |
||||
|
return false; |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
return true; |
||||
|
} |
||||
|
|
||||
|
public virtual async Task<OperationRateLimitingResult> GetStatusAsync(string policyName, OperationRateLimitingContext? context = null) |
||||
|
{ |
||||
|
if (!Options.IsEnabled) |
||||
|
{ |
||||
|
return new OperationRateLimitingResult |
||||
|
{ |
||||
|
IsAllowed = true, |
||||
|
RemainingCount = int.MaxValue, |
||||
|
MaxCount = int.MaxValue, |
||||
|
CurrentCount = 0 |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
context = EnsureContext(context); |
||||
|
var policy = await PolicyProvider.GetAsync(policyName); |
||||
|
var rules = CreateRules(policy); |
||||
|
var ruleResults = new List<OperationRateLimitingRuleResult>(); |
||||
|
|
||||
|
foreach (var rule in rules) |
||||
|
{ |
||||
|
ruleResults.Add(await rule.CheckAsync(context)); |
||||
|
} |
||||
|
|
||||
|
return AggregateResults(ruleResults, policy); |
||||
|
} |
||||
|
|
||||
|
public virtual async Task ResetAsync(string policyName, OperationRateLimitingContext? context = null) |
||||
|
{ |
||||
|
if (!Options.IsEnabled) |
||||
|
{ |
||||
|
return; |
||||
|
} |
||||
|
|
||||
|
context = EnsureContext(context); |
||||
|
var policy = await PolicyProvider.GetAsync(policyName); |
||||
|
var rules = CreateRules(policy); |
||||
|
|
||||
|
foreach (var rule in rules) |
||||
|
{ |
||||
|
await rule.ResetAsync(context); |
||||
|
} |
||||
|
} |
||||
|
|
||||
|
protected virtual OperationRateLimitingContext EnsureContext(OperationRateLimitingContext? context) |
||||
|
{ |
||||
|
context ??= new OperationRateLimitingContext(); |
||||
|
context.ServiceProvider = ServiceProvider; |
||||
|
return context; |
||||
|
} |
||||
|
|
||||
|
protected virtual List<IOperationRateLimitingRule> CreateRules(OperationRateLimitingPolicy policy) |
||||
|
{ |
||||
|
var rules = new List<IOperationRateLimitingRule>(); |
||||
|
|
||||
|
foreach (var ruleDefinition in policy.Rules) |
||||
|
{ |
||||
|
rules.Add(new FixedWindowOperationRateLimitingRule( |
||||
|
policy.Name, |
||||
|
ruleDefinition, |
||||
|
Store, |
||||
|
CurrentUser, |
||||
|
CurrentTenant, |
||||
|
WebClientInfoProvider)); |
||||
|
} |
||||
|
|
||||
|
foreach (var customRuleType in policy.CustomRuleTypes) |
||||
|
{ |
||||
|
rules.Add((IOperationRateLimitingRule)ServiceProvider.GetRequiredService(customRuleType)); |
||||
|
} |
||||
|
|
||||
|
return rules; |
||||
|
} |
||||
|
|
||||
|
protected virtual OperationRateLimitingResult AggregateResults( |
||||
|
List<OperationRateLimitingRuleResult> ruleResults, |
||||
|
OperationRateLimitingPolicy policy) |
||||
|
{ |
||||
|
var isAllowed = ruleResults.All(r => r.IsAllowed); |
||||
|
var mostRestrictive = ruleResults |
||||
|
.OrderBy(r => r.RemainingCount) |
||||
|
.ThenByDescending(r => r.RetryAfter ?? TimeSpan.Zero) |
||||
|
.First(); |
||||
|
|
||||
|
return new OperationRateLimitingResult |
||||
|
{ |
||||
|
IsAllowed = isAllowed, |
||||
|
RemainingCount = mostRestrictive.RemainingCount, |
||||
|
MaxCount = mostRestrictive.MaxCount, |
||||
|
CurrentCount = mostRestrictive.CurrentCount, |
||||
|
RetryAfter = ruleResults.Any(r => !r.IsAllowed && r.RetryAfter.HasValue) |
||||
|
? ruleResults |
||||
|
.Where(r => !r.IsAllowed && r.RetryAfter.HasValue) |
||||
|
.Select(r => r.RetryAfter!.Value) |
||||
|
.Max() |
||||
|
: null, |
||||
|
WindowDuration = mostRestrictive.WindowDuration, |
||||
|
RuleResults = ruleResults |
||||
|
}; |
||||
|
} |
||||
|
|
||||
|
protected virtual void ThrowRateLimitException( |
||||
|
OperationRateLimitingPolicy policy, |
||||
|
OperationRateLimitingResult result, |
||||
|
OperationRateLimitingContext context) |
||||
|
{ |
||||
|
var formatter = context.ServiceProvider.GetRequiredService<IOperationRateLimitingFormatter>(); |
||||
|
|
||||
|
var exception = new AbpOperationRateLimitingException( |
||||
|
policy.Name, |
||||
|
result, |
||||
|
policy.ErrorCode); |
||||
|
|
||||
|
if (result.RetryAfter.HasValue) |
||||
|
{ |
||||
|
exception.SetRetryAfterFormatted(formatter.Format(result.RetryAfter.Value)); |
||||
|
} |
||||
|
|
||||
|
if (result.WindowDuration > TimeSpan.Zero) |
||||
|
{ |
||||
|
exception.SetWindowDescriptionFormatted(formatter.Format(result.WindowDuration)); |
||||
|
} |
||||
|
|
||||
|
if (result.RuleResults != null) |
||||
|
{ |
||||
|
var ruleDetails = new List<Dictionary<string, object>>(); |
||||
|
foreach (var ruleResult in result.RuleResults) |
||||
|
{ |
||||
|
ruleDetails.Add(new Dictionary<string, object> |
||||
|
{ |
||||
|
["RuleName"] = ruleResult.RuleName, |
||||
|
["IsAllowed"] = ruleResult.IsAllowed, |
||||
|
["MaxCount"] = ruleResult.MaxCount, |
||||
|
["RemainingCount"] = ruleResult.RemainingCount, |
||||
|
["CurrentCount"] = ruleResult.CurrentCount, |
||||
|
["WindowDurationSeconds"] = (int)ruleResult.WindowDuration.TotalSeconds, |
||||
|
["WindowDescription"] = ruleResult.WindowDuration > TimeSpan.Zero |
||||
|
? formatter.Format(ruleResult.WindowDuration) |
||||
|
: string.Empty, |
||||
|
["RetryAfterSeconds"] = (int)(ruleResult.RetryAfter?.TotalSeconds ?? 0), |
||||
|
["RetryAfter"] = ruleResult.RetryAfter.HasValue |
||||
|
? formatter.Format(ruleResult.RetryAfter.Value) |
||||
|
: string.Empty |
||||
|
}); |
||||
|
} |
||||
|
|
||||
|
exception.WithData("RuleDetails", ruleDetails); |
||||
|
} |
||||
|
|
||||
|
foreach (var kvp in context.ExtraProperties) |
||||
|
{ |
||||
|
exception.WithData(kvp.Key, kvp.Value!); |
||||
|
} |
||||
|
|
||||
|
throw exception; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,38 @@ |
|||||
|
using System.Threading.Tasks; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public static class OperationRateLimitingCheckerExtensions |
||||
|
{ |
||||
|
public static Task CheckAsync( |
||||
|
this IOperationRateLimitingChecker checker, |
||||
|
string policyName, |
||||
|
string parameter) |
||||
|
{ |
||||
|
return checker.CheckAsync(policyName, new OperationRateLimitingContext { Parameter = parameter }); |
||||
|
} |
||||
|
|
||||
|
public static Task<bool> IsAllowedAsync( |
||||
|
this IOperationRateLimitingChecker checker, |
||||
|
string policyName, |
||||
|
string parameter) |
||||
|
{ |
||||
|
return checker.IsAllowedAsync(policyName, new OperationRateLimitingContext { Parameter = parameter }); |
||||
|
} |
||||
|
|
||||
|
public static Task<OperationRateLimitingResult> GetStatusAsync( |
||||
|
this IOperationRateLimitingChecker checker, |
||||
|
string policyName, |
||||
|
string parameter) |
||||
|
{ |
||||
|
return checker.GetStatusAsync(policyName, new OperationRateLimitingContext { Parameter = parameter }); |
||||
|
} |
||||
|
|
||||
|
public static Task ResetAsync( |
||||
|
this IOperationRateLimitingChecker checker, |
||||
|
string policyName, |
||||
|
string parameter) |
||||
|
{ |
||||
|
return checker.ResetAsync(policyName, new OperationRateLimitingContext { Parameter = parameter }); |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,33 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
using Microsoft.Extensions.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public class OperationRateLimitingContext |
||||
|
{ |
||||
|
/// <summary>
|
||||
|
/// Optional parameter passed by the caller.
|
||||
|
/// Used as the partition key by PartitionByParameter() (required),
|
||||
|
/// and as a fallback by PartitionByEmail() and PartitionByPhoneNumber().
|
||||
|
/// Can be email, phone number, user id, resource id, or any string.
|
||||
|
/// </summary>
|
||||
|
public string? Parameter { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Additional properties that can be read by custom <see cref="IOperationRateLimitingRule"/> implementations
|
||||
|
/// and are forwarded to the exception's Data dictionary when the rate limit is exceeded.
|
||||
|
/// </summary>
|
||||
|
public Dictionary<string, object?> ExtraProperties { get; set; } = new(); |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// The service provider for resolving services.
|
||||
|
/// Set automatically by the checker.
|
||||
|
/// </summary>
|
||||
|
public IServiceProvider ServiceProvider { get; set; } = default!; |
||||
|
|
||||
|
public T GetRequiredService<T>() where T : notnull |
||||
|
=> ServiceProvider.GetRequiredService<T>(); |
||||
|
|
||||
|
public T? GetService<T>() => ServiceProvider.GetService<T>(); |
||||
|
} |
||||
@ -0,0 +1,24 @@ |
|||||
|
using System; |
||||
|
using System.Collections.Generic; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public class OperationRateLimitingResult |
||||
|
{ |
||||
|
public bool IsAllowed { get; set; } |
||||
|
|
||||
|
public int RemainingCount { get; set; } |
||||
|
|
||||
|
public int MaxCount { get; set; } |
||||
|
|
||||
|
public int CurrentCount { get; set; } |
||||
|
|
||||
|
public TimeSpan? RetryAfter { get; set; } |
||||
|
|
||||
|
public TimeSpan WindowDuration { get; set; } |
||||
|
|
||||
|
/// <summary>
|
||||
|
/// Detailed results per rule (for composite policies).
|
||||
|
/// </summary>
|
||||
|
public List<OperationRateLimitingRuleResult>? RuleResults { get; set; } |
||||
|
} |
||||
@ -0,0 +1,20 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public class OperationRateLimitingRuleResult |
||||
|
{ |
||||
|
public string RuleName { get; set; } = default!; |
||||
|
|
||||
|
public bool IsAllowed { get; set; } |
||||
|
|
||||
|
public int CurrentCount { get; set; } |
||||
|
|
||||
|
public int RemainingCount { get; set; } |
||||
|
|
||||
|
public int MaxCount { get; set; } |
||||
|
|
||||
|
public TimeSpan? RetryAfter { get; set; } |
||||
|
|
||||
|
public TimeSpan WindowDuration { get; set; } |
||||
|
} |
||||
@ -0,0 +1,48 @@ |
|||||
|
using System; |
||||
|
using Volo.Abp.ExceptionHandling; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public class AbpOperationRateLimitingException : BusinessException, IHasHttpStatusCode |
||||
|
{ |
||||
|
public string PolicyName { get; } |
||||
|
|
||||
|
public OperationRateLimitingResult Result { get; } |
||||
|
|
||||
|
public int HttpStatusCode => 429; |
||||
|
|
||||
|
public AbpOperationRateLimitingException( |
||||
|
string policyName, |
||||
|
OperationRateLimitingResult result, |
||||
|
string? errorCode = null) |
||||
|
: base(code: errorCode ?? ResolveDefaultErrorCode(result)) |
||||
|
{ |
||||
|
PolicyName = policyName; |
||||
|
Result = result; |
||||
|
|
||||
|
WithData("PolicyName", policyName); |
||||
|
WithData("MaxCount", result.MaxCount); |
||||
|
WithData("CurrentCount", result.CurrentCount); |
||||
|
WithData("RemainingCount", result.RemainingCount); |
||||
|
WithData("RetryAfterSeconds", (int)(result.RetryAfter?.TotalSeconds ?? 0)); |
||||
|
WithData("RetryAfterMinutes", (int)(result.RetryAfter?.TotalMinutes ?? 0)); |
||||
|
WithData("WindowDurationSeconds", (int)result.WindowDuration.TotalSeconds); |
||||
|
} |
||||
|
|
||||
|
internal void SetRetryAfterFormatted(string formattedRetryAfter) |
||||
|
{ |
||||
|
WithData("RetryAfter", formattedRetryAfter); |
||||
|
} |
||||
|
|
||||
|
internal void SetWindowDescriptionFormatted(string formattedWindowDescription) |
||||
|
{ |
||||
|
WithData("WindowDescription", formattedWindowDescription); |
||||
|
} |
||||
|
|
||||
|
private static string ResolveDefaultErrorCode(OperationRateLimitingResult result) |
||||
|
{ |
||||
|
return result.RetryAfter.HasValue |
||||
|
? AbpOperationRateLimitingErrorCodes.ExceedLimit |
||||
|
: AbpOperationRateLimitingErrorCodes.ExceedLimitPermanently; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,68 @@ |
|||||
|
using System; |
||||
|
using Microsoft.Extensions.Localization; |
||||
|
using Volo.Abp.DependencyInjection; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public class DefaultOperationRateLimitingFormatter |
||||
|
: IOperationRateLimitingFormatter, ITransientDependency |
||||
|
{ |
||||
|
protected IStringLocalizer<AbpOperationRateLimitingResource> Localizer { get; } |
||||
|
|
||||
|
public DefaultOperationRateLimitingFormatter( |
||||
|
IStringLocalizer<AbpOperationRateLimitingResource> localizer) |
||||
|
{ |
||||
|
Localizer = localizer; |
||||
|
} |
||||
|
|
||||
|
public virtual string Format(TimeSpan duration) |
||||
|
{ |
||||
|
if (duration.TotalDays >= 365) |
||||
|
{ |
||||
|
var years = (int)(duration.TotalDays / 365); |
||||
|
var remainingDays = (int)(duration.TotalDays % 365); |
||||
|
var months = remainingDays / 30; |
||||
|
return months > 0 |
||||
|
? Localizer["RetryAfter:YearsAndMonths", years, months] |
||||
|
: Localizer["RetryAfter:Years", years]; |
||||
|
} |
||||
|
|
||||
|
if (duration.TotalDays >= 30) |
||||
|
{ |
||||
|
var months = (int)(duration.TotalDays / 30); |
||||
|
var remainingDays = (int)(duration.TotalDays % 30); |
||||
|
return remainingDays > 0 |
||||
|
? Localizer["RetryAfter:MonthsAndDays", months, remainingDays] |
||||
|
: Localizer["RetryAfter:Months", months]; |
||||
|
} |
||||
|
|
||||
|
if (duration.TotalDays >= 1) |
||||
|
{ |
||||
|
var days = (int)duration.TotalDays; |
||||
|
var hours = duration.Hours; |
||||
|
return hours > 0 |
||||
|
? Localizer["RetryAfter:DaysAndHours", days, hours] |
||||
|
: Localizer["RetryAfter:Days", days]; |
||||
|
} |
||||
|
|
||||
|
if (duration.TotalHours >= 1) |
||||
|
{ |
||||
|
var hours = (int)duration.TotalHours; |
||||
|
var minutes = duration.Minutes; |
||||
|
return minutes > 0 |
||||
|
? Localizer["RetryAfter:HoursAndMinutes", hours, minutes] |
||||
|
: Localizer["RetryAfter:Hours", hours]; |
||||
|
} |
||||
|
|
||||
|
if (duration.TotalMinutes >= 1) |
||||
|
{ |
||||
|
var minutes = (int)duration.TotalMinutes; |
||||
|
var seconds = duration.Seconds; |
||||
|
return seconds > 0 |
||||
|
? Localizer["RetryAfter:MinutesAndSeconds", minutes, seconds] |
||||
|
: Localizer["RetryAfter:Minutes", minutes]; |
||||
|
} |
||||
|
|
||||
|
return Localizer["RetryAfter:Seconds", (int)duration.TotalSeconds]; |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,8 @@ |
|||||
|
using System; |
||||
|
|
||||
|
namespace Volo.Abp.OperationRateLimiting; |
||||
|
|
||||
|
public interface IOperationRateLimitingFormatter |
||||
|
{ |
||||
|
string Format(TimeSpan duration); |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "ar", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "تم تجاوز حد معدل العملية. يمكنك المحاولة مرة أخرى بعد {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} سنة/سنوات", |
||||
|
"RetryAfter:YearsAndMonths": "{0} سنة/سنوات و {1} شهر/أشهر", |
||||
|
"RetryAfter:Months": "{0} شهر/أشهر", |
||||
|
"RetryAfter:MonthsAndDays": "{0} شهر/أشهر و {1} يوم/أيام", |
||||
|
"RetryAfter:Days": "{0} يوم/أيام", |
||||
|
"RetryAfter:DaysAndHours": "{0} يوم/أيام و {1} ساعة/ساعات", |
||||
|
"RetryAfter:Hours": "{0} ساعة/ساعات", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} ساعة/ساعات و {1} دقيقة/دقائق", |
||||
|
"RetryAfter:Minutes": "{0} دقيقة/دقائق", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} دقيقة/دقائق و {1} ثانية/ثوان", |
||||
|
"RetryAfter:Seconds": "{0} ثانية/ثوان", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "تم تجاوز حد معدل العملية. هذا الطلب مرفوض بشكل دائم." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "cs", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Překročen limit rychlosti operace. Můžete to zkusit znovu za {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} rok(y/let)", |
||||
|
"RetryAfter:YearsAndMonths": "{0} rok(y/let) a {1} měsíc(e/ů)", |
||||
|
"RetryAfter:Months": "{0} měsíc(e/ů)", |
||||
|
"RetryAfter:MonthsAndDays": "{0} měsíc(e/ů) a {1} den/dny/dní", |
||||
|
"RetryAfter:Days": "{0} den/dny/dní", |
||||
|
"RetryAfter:DaysAndHours": "{0} den/dny/dní a {1} hodina/hodiny/hodin", |
||||
|
"RetryAfter:Hours": "{0} hodina/hodiny/hodin", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} hodina/hodiny/hodin a {1} minuta/minuty/minut", |
||||
|
"RetryAfter:Minutes": "{0} minuta/minuty/minut", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minuta/minuty/minut a {1} sekunda/sekundy/sekund", |
||||
|
"RetryAfter:Seconds": "{0} sekunda/sekundy/sekund", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Byl překročen limit četnosti operace. Tento požadavek je trvale zamítnut." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "de", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Betriebsratenlimit überschritten. Sie können es nach {RetryAfter} erneut versuchen.", |
||||
|
"RetryAfter:Years": "{0} Jahr(e)", |
||||
|
"RetryAfter:YearsAndMonths": "{0} Jahr(e) und {1} Monat(e)", |
||||
|
"RetryAfter:Months": "{0} Monat(e)", |
||||
|
"RetryAfter:MonthsAndDays": "{0} Monat(e) und {1} Tag(e)", |
||||
|
"RetryAfter:Days": "{0} Tag(e)", |
||||
|
"RetryAfter:DaysAndHours": "{0} Tag(e) und {1} Stunde(n)", |
||||
|
"RetryAfter:Hours": "{0} Stunde(n)", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} Stunde(n) und {1} Minute(n)", |
||||
|
"RetryAfter:Minutes": "{0} Minute(n)", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} Minute(n) und {1} Sekunde(n)", |
||||
|
"RetryAfter:Seconds": "{0} Sekunde(n)", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Das Vorgangshäufigkeitslimit wurde überschritten. Diese Anfrage wird dauerhaft abgelehnt." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "el", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Υπέρβαση ορίου ρυθμού λειτουργίας. Μπορείτε να δοκιμάσετε ξανά μετά από {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} έτος/η", |
||||
|
"RetryAfter:YearsAndMonths": "{0} έτος/η και {1} μήνας/ες", |
||||
|
"RetryAfter:Months": "{0} μήνας/ες", |
||||
|
"RetryAfter:MonthsAndDays": "{0} μήνας/ες και {1} ημέρα/ες", |
||||
|
"RetryAfter:Days": "{0} ημέρα/ες", |
||||
|
"RetryAfter:DaysAndHours": "{0} ημέρα/ες και {1} ώρα/ες", |
||||
|
"RetryAfter:Hours": "{0} ώρα/ες", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} ώρα/ες και {1} λεπτό/ά", |
||||
|
"RetryAfter:Minutes": "{0} λεπτό/ά", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} λεπτό/ά και {1} δευτερόλεπτο/α", |
||||
|
"RetryAfter:Seconds": "{0} δευτερόλεπτο/α", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Υπερβλήθηκε το όριο συχνότητας λειτουργίας. Αυτό το αίτημα απορρίπτεται μόνιμα." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "en-GB", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Operation rate limit exceeded. You can try again after {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} year(s)", |
||||
|
"RetryAfter:YearsAndMonths": "{0} year(s) and {1} month(s)", |
||||
|
"RetryAfter:Months": "{0} month(s)", |
||||
|
"RetryAfter:MonthsAndDays": "{0} month(s) and {1} day(s)", |
||||
|
"RetryAfter:Days": "{0} day(s)", |
||||
|
"RetryAfter:DaysAndHours": "{0} day(s) and {1} hour(s)", |
||||
|
"RetryAfter:Hours": "{0} hour(s)", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} hour(s) and {1} minute(s)", |
||||
|
"RetryAfter:Minutes": "{0} minute(s)", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minute(s) and {1} second(s)", |
||||
|
"RetryAfter:Seconds": "{0} second(s)", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Operation rate limit exceeded. This request is permanently denied." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "en", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Operation rate limit exceeded. You can try again after {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} year(s)", |
||||
|
"RetryAfter:YearsAndMonths": "{0} year(s) and {1} month(s)", |
||||
|
"RetryAfter:Months": "{0} month(s)", |
||||
|
"RetryAfter:MonthsAndDays": "{0} month(s) and {1} day(s)", |
||||
|
"RetryAfter:Days": "{0} day(s)", |
||||
|
"RetryAfter:DaysAndHours": "{0} day(s) and {1} hour(s)", |
||||
|
"RetryAfter:Hours": "{0} hour(s)", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} hour(s) and {1} minute(s)", |
||||
|
"RetryAfter:Minutes": "{0} minute(s)", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minute(s) and {1} second(s)", |
||||
|
"RetryAfter:Seconds": "{0} second(s)", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Operation rate limit exceeded. This request is permanently denied." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "es", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Se ha excedido el límite de tasa de operación. Puede intentarlo de nuevo después de {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} año(s)", |
||||
|
"RetryAfter:YearsAndMonths": "{0} año(s) y {1} mes(es)", |
||||
|
"RetryAfter:Months": "{0} mes(es)", |
||||
|
"RetryAfter:MonthsAndDays": "{0} mes(es) y {1} día(s)", |
||||
|
"RetryAfter:Days": "{0} día(s)", |
||||
|
"RetryAfter:DaysAndHours": "{0} día(s) y {1} hora(s)", |
||||
|
"RetryAfter:Hours": "{0} hora(s)", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} hora(s) y {1} minuto(s)", |
||||
|
"RetryAfter:Minutes": "{0} minuto(s)", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minuto(s) y {1} segundo(s)", |
||||
|
"RetryAfter:Seconds": "{0} segundo(s)", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Se superó el límite de frecuencia de operación. Esta solicitud está permanentemente denegada." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "fa", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "محدودیت نرخ عملیات فراتر رفته است. میتوانید بعد از {RetryAfter} دوباره تلاش کنید.", |
||||
|
"RetryAfter:Years": "{0} سال", |
||||
|
"RetryAfter:YearsAndMonths": "{0} سال و {1} ماه", |
||||
|
"RetryAfter:Months": "{0} ماه", |
||||
|
"RetryAfter:MonthsAndDays": "{0} ماه و {1} روز", |
||||
|
"RetryAfter:Days": "{0} روز", |
||||
|
"RetryAfter:DaysAndHours": "{0} روز و {1} ساعت", |
||||
|
"RetryAfter:Hours": "{0} ساعت", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} ساعت و {1} دقیقه", |
||||
|
"RetryAfter:Minutes": "{0} دقیقه", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} دقیقه و {1} ثانیه", |
||||
|
"RetryAfter:Seconds": "{0} ثانیه", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "محدودیت نرخ عملیات از حد مجاز فراتر رفت. این درخواست به طور دائمی رد شده است." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "fi", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Toiminnon nopeusraja ylitetty. Voit yrittää uudelleen {RetryAfter} kuluttua.", |
||||
|
"RetryAfter:Years": "{0} vuosi/vuotta", |
||||
|
"RetryAfter:YearsAndMonths": "{0} vuosi/vuotta ja {1} kuukausi/kuukautta", |
||||
|
"RetryAfter:Months": "{0} kuukausi/kuukautta", |
||||
|
"RetryAfter:MonthsAndDays": "{0} kuukausi/kuukautta ja {1} päivä/päivää", |
||||
|
"RetryAfter:Days": "{0} päivä/päivää", |
||||
|
"RetryAfter:DaysAndHours": "{0} päivä/päivää ja {1} tunti/tuntia", |
||||
|
"RetryAfter:Hours": "{0} tunti/tuntia", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} tunti/tuntia ja {1} minuutti/minuuttia", |
||||
|
"RetryAfter:Minutes": "{0} minuutti/minuuttia", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minuutti/minuuttia ja {1} sekunti/sekuntia", |
||||
|
"RetryAfter:Seconds": "{0} sekunti/sekuntia", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Toiminnan nopeusraja ylitettiin. Tämä pyyntö on pysyvästi hylätty." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "fr", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Limite de taux d'opération dépassée. Vous pouvez réessayer après {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} an(s)", |
||||
|
"RetryAfter:YearsAndMonths": "{0} an(s) et {1} mois", |
||||
|
"RetryAfter:Months": "{0} mois", |
||||
|
"RetryAfter:MonthsAndDays": "{0} mois et {1} jour(s)", |
||||
|
"RetryAfter:Days": "{0} jour(s)", |
||||
|
"RetryAfter:DaysAndHours": "{0} jour(s) et {1} heure(s)", |
||||
|
"RetryAfter:Hours": "{0} heure(s)", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} heure(s) et {1} minute(s)", |
||||
|
"RetryAfter:Minutes": "{0} minute(s)", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minute(s) et {1} seconde(s)", |
||||
|
"RetryAfter:Seconds": "{0} seconde(s)", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "La limite de fréquence d'opération a été dépassée. Cette demande est définitivement refusée." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "hi", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "ऑपरेशन दर सीमा पार हो गई। आप {RetryAfter} के बाद पुनः प्रयास कर सकते हैं।", |
||||
|
"RetryAfter:Years": "{0} वर्ष", |
||||
|
"RetryAfter:YearsAndMonths": "{0} वर्ष और {1} महीना/महीने", |
||||
|
"RetryAfter:Months": "{0} महीना/महीने", |
||||
|
"RetryAfter:MonthsAndDays": "{0} महीना/महीने और {1} दिन", |
||||
|
"RetryAfter:Days": "{0} दिन", |
||||
|
"RetryAfter:DaysAndHours": "{0} दिन और {1} घंटा/घंटे", |
||||
|
"RetryAfter:Hours": "{0} घंटा/घंटे", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} घंटा/घंटे और {1} मिनट", |
||||
|
"RetryAfter:Minutes": "{0} मिनट", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} मिनट और {1} सेकंड", |
||||
|
"RetryAfter:Seconds": "{0} सेकंड", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "ऑपरेशन दर सीमा पार हो गई। यह अनुरोध स्थायी रूप से अस्वीकृत है।" |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "hr", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Prekoračeno ograničenje brzine operacije. Možete pokušati ponovo nakon {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} godina/e", |
||||
|
"RetryAfter:YearsAndMonths": "{0} godina/e i {1} mjesec/i", |
||||
|
"RetryAfter:Months": "{0} mjesec/i", |
||||
|
"RetryAfter:MonthsAndDays": "{0} mjesec/i i {1} dan/a", |
||||
|
"RetryAfter:Days": "{0} dan/a", |
||||
|
"RetryAfter:DaysAndHours": "{0} dan/a i {1} sat/i", |
||||
|
"RetryAfter:Hours": "{0} sat/i", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} sat/i i {1} minuta/e", |
||||
|
"RetryAfter:Minutes": "{0} minuta/e", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minuta/e i {1} sekunda/e", |
||||
|
"RetryAfter:Seconds": "{0} sekunda/e", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Prekoračeno je ograničenje brzine operacije. Ovaj zahtjev je trajno odbijen." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "hu", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "A műveleti sebességkorlát túllépve. Újra próbálkozhat {RetryAfter} múlva.", |
||||
|
"RetryAfter:Years": "{0} év", |
||||
|
"RetryAfter:YearsAndMonths": "{0} év és {1} hónap", |
||||
|
"RetryAfter:Months": "{0} hónap", |
||||
|
"RetryAfter:MonthsAndDays": "{0} hónap és {1} nap", |
||||
|
"RetryAfter:Days": "{0} nap", |
||||
|
"RetryAfter:DaysAndHours": "{0} nap és {1} óra", |
||||
|
"RetryAfter:Hours": "{0} óra", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} óra és {1} perc", |
||||
|
"RetryAfter:Minutes": "{0} perc", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} perc és {1} másodperc", |
||||
|
"RetryAfter:Seconds": "{0} másodperc", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "A műveleti ráta korlátja túllépve. Ez a kérés véglegesen elutasítva." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "is", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Aðgerðarhraðatakmörk náð. Þú getur reynt aftur eftir {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} ár", |
||||
|
"RetryAfter:YearsAndMonths": "{0} ár og {1} mánuð(ir)", |
||||
|
"RetryAfter:Months": "{0} mánuð(ur/ir)", |
||||
|
"RetryAfter:MonthsAndDays": "{0} mánuð(ur/ir) og {1} dag(ur/ar)", |
||||
|
"RetryAfter:Days": "{0} dag(ur/ar)", |
||||
|
"RetryAfter:DaysAndHours": "{0} dag(ur/ar) og {1} klukkustund(ir)", |
||||
|
"RetryAfter:Hours": "{0} klukkustund(ir)", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} klukkustund(ir) og {1} mínúta/úr", |
||||
|
"RetryAfter:Minutes": "{0} mínúta/úr", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} mínúta/úr og {1} sekúnda/úr", |
||||
|
"RetryAfter:Seconds": "{0} sekúnda/úr", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Farið var yfir takmörk á rekstrartíðni. Þessari beiðni er varanlega hafnað." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "it", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Limite di frequenza operazione superato. Puoi riprovare dopo {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} anno/i", |
||||
|
"RetryAfter:YearsAndMonths": "{0} anno/i e {1} mese/i", |
||||
|
"RetryAfter:Months": "{0} mese/i", |
||||
|
"RetryAfter:MonthsAndDays": "{0} mese/i e {1} giorno/i", |
||||
|
"RetryAfter:Days": "{0} giorno/i", |
||||
|
"RetryAfter:DaysAndHours": "{0} giorno/i e {1} ora/e", |
||||
|
"RetryAfter:Hours": "{0} ora/e", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} ora/e e {1} minuto/i", |
||||
|
"RetryAfter:Minutes": "{0} minuto/i", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minuto/i e {1} secondo/i", |
||||
|
"RetryAfter:Seconds": "{0} secondo/i", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Limite di frequenza operazione superato. Questa richiesta è permanentemente negata." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "nl", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Bewerkingssnelheidslimiet overschreden. U kunt het opnieuw proberen na {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} jaar", |
||||
|
"RetryAfter:YearsAndMonths": "{0} jaar en {1} maand(en)", |
||||
|
"RetryAfter:Months": "{0} maand(en)", |
||||
|
"RetryAfter:MonthsAndDays": "{0} maand(en) en {1} dag(en)", |
||||
|
"RetryAfter:Days": "{0} dag(en)", |
||||
|
"RetryAfter:DaysAndHours": "{0} dag(en) en {1} uur", |
||||
|
"RetryAfter:Hours": "{0} uur", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} uur en {1} minuut/minuten", |
||||
|
"RetryAfter:Minutes": "{0} minuut/minuten", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minuut/minuten en {1} seconde(n)", |
||||
|
"RetryAfter:Seconds": "{0} seconde(n)", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Het bewerkingsfrequentielimiet is overschreden. Dit verzoek wordt permanent geweigerd." |
||||
|
} |
||||
|
} |
||||
@ -0,0 +1,18 @@ |
|||||
|
{ |
||||
|
"culture": "pl-PL", |
||||
|
"texts": { |
||||
|
"Volo.Abp.OperationRateLimiting:010001": "Przekroczono limit częstotliwości operacji. Możesz spróbować ponownie po {RetryAfter}.", |
||||
|
"RetryAfter:Years": "{0} rok/lat", |
||||
|
"RetryAfter:YearsAndMonths": "{0} rok/lat i {1} miesiąc/miesięcy", |
||||
|
"RetryAfter:Months": "{0} miesiąc/miesięcy", |
||||
|
"RetryAfter:MonthsAndDays": "{0} miesiąc/miesięcy i {1} dzień/dni", |
||||
|
"RetryAfter:Days": "{0} dzień/dni", |
||||
|
"RetryAfter:DaysAndHours": "{0} dzień/dni i {1} godzina/godzin", |
||||
|
"RetryAfter:Hours": "{0} godzina/godzin", |
||||
|
"RetryAfter:HoursAndMinutes": "{0} godzina/godzin i {1} minuta/minut", |
||||
|
"RetryAfter:Minutes": "{0} minuta/minut", |
||||
|
"RetryAfter:MinutesAndSeconds": "{0} minuta/minut i {1} sekunda/sekund", |
||||
|
"RetryAfter:Seconds": "{0} sekunda/sekund", |
||||
|
"Volo.Abp.OperationRateLimiting:010002": "Przekroczono limit częstotliwości operacji. To żądanie jest trwale odrzucone." |
||||
|
} |
||||
|
} |
||||