Casbin.NET authorization models for .NET applications
An authorization library that supports access control models like ACL, RBAC, ABAC in .NET (C#)
At a glance
- What is it?
- Casbin.NET is an Apache-licensed authorization library for .NET applications that need ACL, RBAC, ABAC, REST-style, deny-override, or priority-based decisions. Its trade-off is that policy behavior depends on model configuration, matchers, adapters, and role managers that application teams must understand and test.
- Who is it for?
- Adopt Casbin.NET when a .NET application needs one enforcement path across several authorization models or tenant boundaries. Do not choose it if authorization must remain fixed in application code or if the team will not verify matcher semantics, adapter behavior, and policy consistency.
- Can I use it commercially?
- Yes. Apache-2.0 is a permissive licence: you can use, modify and sell software built on it, as long as you keep its copyright and licence notices.
- Is it still maintained?
- Yes. The repository last received commits 3 days ago.
- What is it written in?
- Mainly C#, according to GitHub's language statistics.
Answers come from the project's GitHub data, last synced on October 23, 2026, and from our analysis. They are not legal advice.
Editorial analysis
Where Casbin.NET fits in a .NET authorization stack
Casbin.NET addresses application authorization rather than authentication. It does not decide whether a user has signed in or how a credential is verified. Its job is to evaluate whether a request, represented by fields such as a subject, object, and action, should be allowed under a configured policy.
The library is aimed at .NET and C# applications that need more than a single hard-coded ownership check. The README lists ACL, ACL with a superuser, ACL without users, ACL without resources, RBAC, resource roles, domains and tenants, ABAC, REST-style paths, deny-override, and prioritized rules. This range is useful when different services or resources express access in different forms but still need a shared enforcement library.
It is also relevant to multi-tenant software because domain-aware RBAC can assign different roles to the same user in different domains. A service that needs fine-grained access for a resource owner, however, may find direct application-level authorization simpler. Casbin.NET adds a policy layer, model files, storage decisions, and matcher evaluation. That abstraction is justified when the policy vocabulary is shared across components or expected to change independently of C# code.
Casbin.NET's PERM model and policy evaluation
Casbin.NET represents an access-control model through the PERM metamodel: Policy, Effect, Request, and Matchers. The request definition describes the values supplied for one authorization decision. The policy definition describes the fields stored in policy rules. The matcher expression compares those values, and the policy effect determines how matches become an allow or deny result.
The README's basic ACL model uses three request fields and three policy fields: `sub`, `obj`, and `act`. Its matcher requires equality across all three pairs. Its effect permits a decision when at least one matched policy entry has `p.eft == allow`. Policies then connect a subject, object, and action. For example, separate rules grant `alice` access to read `data1` and grant `bob` access to write `data2`.
This design separates the decision mechanism from a particular access-control style. RBAC can add roles through the model and role manager. ABAC can read request attributes with expressions such as `resource.Owner`. REST-style matching can consider paths such as `/res/:id` and HTTP methods. Deny-override can use both allow and deny policies, while priority orders rules in a way the README compares to firewall rules. The cost is behavioral complexity: a one-line matcher change can alter access across the entire policy set, so model files deserve direct tests.
Casbin.NET model files for changing access rules
The basic ACL configuration is concrete enough to use as a reference fixture:
[request_definition]
r = sub, obj, act
[policy_definition]
p = sub, obj, act
[policy_effect]
e = some(where (p.eft == allow))
[matchers]
m = r.sub == p.sub && r.obj == p.obj && r.act == p.actIts companion policy grants two unrelated actions:
p, alice, data1, read
p, bob, data2, writeThe matcher uses strict equality, so changes to object names or action strings must be reflected in policy data. That predictability is a benefit for ACL. RBAC introduces role relationships and the role manager, while domain RBAC changes the request and policy structure to include tenant context. ABAC changes the matcher from identity equality to attribute access. REST-style policies add path and method matching.
These models are not interchangeable labels. Each defines a different meaning for a policy rule and requires authorization cases tailored to its fields. The README also documents multi-line model syntax by appending `\` to a line. That feature can improve long matcher definitions, but formatting becomes another part of the policy contract that reviewers must validate.
Preparing the first Casbin.NET policy without guessed APIs
The README does not show a package installation command, a C# Enforcer construction call, or the file-loading API needed for a complete executable first-use tutorial. It links to the `Casbin.NET` package on NuGet and directs readers to Casbin documentation, so this article does not invent those commands or API names.
A team can still prepare the two exact ACL fixtures documented by the README. Put the model configuration in the model file expected by the loading instructions in the project's current documentation, and put the rules in the corresponding policy file:
p, alice, data1, read
p, bob, data2, writeThe expected first decision is that a request carrying `alice`, `data1`, and `read` is allowed by the ACL fixture. A request carrying `bob`, `data1`, and `read` is not matched by either rule. The README does not specify the exact C# request API, so verification must use the official package documentation rather than a guessed method call.
This limitation makes version-specific documentation important. Casbin.NET was listed at release `v2.21.2` on 2026-06-16. A project should follow the setup instructions for the package version it actually selects rather than copying an example written for an unspecified release.
Persistence and multi-node policy consistency
Casbin.NET's README includes sections for policy management, policy persistence, consistency between multiple nodes, and incremental filtered policy updates. The repository also contains `INCREMENTAL_FILTERED_POLICY.md`, indicating that filtered policy handling has a dedicated design document. The README excerpt does not identify concrete adapters, connection strings, retry behavior, or consistency guarantees.
This is a real adoption boundary. A file or in-memory policy may be sufficient for a small service, while production use across processes can require synchronized updates and clear behavior when one node has received a change while another has not. The project addresses policy consistency, but the README text does not state the protocol or its operational prerequisites. Verify that the chosen persistence path implements the policy-management operations required by the application before treating multiple instances as equivalent.
Model reloading is another boundary. The README does not say when a changed model or policy is reloaded. Editing a file must not be treated as proof that every live Enforcer has adopted the change. Inspect the selected adapter and middleware setup, and add a test that exposes whether a running instance can still answer using an obsolete rule.
Maintenance, releases, middleware, and licensing
The repository is not archived, and its last push was on 2026-08-15. Three releases were published on 2026-06-16: `v2.21.0`, `v2.21.1`, and `v2.21.2`. Those dates establish recent repository activity and release work, although the README does not describe the changes between those versions.
Upgrade cost will depend on how directly application code depends on Casbin.NET APIs and on whether existing model and policy fixtures remain compatible. Pinning the package version is more important here than for a stateless utility because authorization behavior can span many tests. Review the release notes for the selected version before changing it, especially if middleware, persistence extensions, or Enforcer APIs are involved.
The README lists middlewares, but it does not identify their supported frameworks or configuration. The repository contains `azure-pipelines.yml`, `Casbin.UnitTests/`, `Casbin.Benchmark/`, and `Casbin.NET.sln`, indicating dedicated build, test, and benchmark areas. Those files do not by themselves establish which middleware configuration is compatible with a particular application.
Casbin.NET uses the `Apache-2.0` license, and the repository includes `LICENSE` and `NOTICE` files. This states the project's licensing model, but organizations still need to review those files and applicable dependencies for their own compliance process.
Direct C# authorization as the narrower alternative
Casbin.NET is a poor fit when access control has one simple rule and the application already owns a clear authorization component. Adding PERM configuration, policy persistence, role management, and enforcement calls can expand the surface area without creating a corresponding benefit. It is also unsuitable when business rules cannot be expressed safely in the configured matcher language or when operators require fixed, code-reviewed logic rather than policy data.
A concrete alternative is direct ownership authorization in the .NET service. For requests such as `resource.Owner == currentUser`, an ordinary C# authorization handler can express the rule close to the endpoint or application service, without a policy file. The trade-off is clear: direct authorization is easier to inspect for one owner-based use case, while Casbin.NET is more relevant when ACL, RBAC, domain separation, ABAC, and shared policy management must coexist.
Casbin.NET can also require middleware integration for hosted web applications, although the README does not show the relevant class names or setup. Confirm the middleware and persistence choices before replacing a working authorization path. The library's breadth is useful, but it is not evidence that every application should use it.
Editorial conclusion
Adopt Casbin.NET when a .NET application needs one enforcement path across several authorization models or tenant boundaries. Do not choose it if authorization must remain fixed in application code or if the team will not verify matcher semantics, adapter behavior, and policy consistency. For Casbin.NET specifically, the first adoption check should be a request that crosses RBAC resource roles and ABAC attributes, because that exercise tests the central configuration-driven design rather than only the simplest ACL case.
Frequently asked questions
Which access-control models does Casbin.NET support?
The README lists ACL, RBAC, domain-aware RBAC, ABAC, REST-style paths, deny-override, prioritized policies, and ACL variants with superusers or missing users or resources.
How does Casbin.NET evaluate an authorization request?
A model defines the request, policy, effect, and matcher through the PERM metamodel. The matcher compares the request with policy fields, and the policy effect determines the resulting decision.
How do I install Casbin.NET and load its first policy?
The README links to the `Casbin.NET` package on NuGet but does not include an installation command or the C# loading API. It does provide complete ACL model and policy examples that can serve as initial fixtures once the missing setup details come from the official package documentation.
Official sources
Add this badge to your README
If you maintain this project, the badge below links readers to this analysis and shows its maintenance status from the daily GitHub snapshot. Paste the markdown into your README; add ?metric=license or ?metric=stars to the image URL for a different field.
[](https://hysenlabs.com/projects/apache-casbin-casbin-net)Was this useful?