# Netrock

> Add a route constraint for path parameter validation Use when this capability is needed.

- Skill: `tomevault-io/netrock` (Agent Skill, multi-file: 2 files)
- Install (CLI): `npx skillmds@latest add tomevault-io/netrock`
- Raw SKILL.md: https://api.skillmd.com/api/skills/tomevault-io/netrock/raw
- Safety review: pending (external: skill-scanner PASS, skillspector PASS)
- Works with: Claude Code, Claude.ai, OpenAI Codex
- Category: Coding & Dev Tools
- Author: tomevault-io (https://skillmd.com/u/tomevault-io)
- Updated: 2026-09-17
- Page: https://skillmd.com/skills/tomevault-io/netrock

---


Adds a route constraint for validating string path parameters at the routing layer.

## Steps

1. Create `src/backend/MyProject.WebApi/Routing/{Name}RouteConstraint.cs`:
   ```csharp
   public partial class {Name}RouteConstraint : IRouteConstraint
   {
       public bool Match(HttpContext? httpContext, IRouter? route, string routeKey,
           RouteValueDictionary values, RouteDirection routeDirection)
       {
           if (!values.TryGetValue(routeKey, out var value) || value is not string s)
               return false;
           return s.Length <= 100 && Pattern().IsMatch(s);
       }

       [GeneratedRegex(@"^[A-Za-z0-9._-]+$")]
       private static partial Regex Pattern();
   }
   ```
2. Register in `Program.cs` inside `AddRouting`:
   ```csharp
   options.ConstraintMap.Add("myConstraint", typeof({Name}RouteConstraint));
   ```
3. Use in routes: `[HttpGet("items/{id:myConstraint}")]`
4. Non-matching routes return 404 automatically - no controller code needed
5. Verify: `dotnet build src/backend/MyProject.slnx`

---
> Source: [fpindej/netrock](https://github.com/fpindej/netrock) — distributed by [TomeVault](https://tomevault.io).
<!-- tomevault:4.0:skill_md:2026-06-18 -->

