.cursor/skills/razor-pages-patterns/SKILL.md
Best practices for building production-grade ASP.NET Core Razor Pages applications. Focuses on structure, lifecycle, binding, validation, security, and maintainability in web apps using Razor Pages as the primary UI framework. Use when building Razor Pages applications, designing PageModels and handlers, implementing model binding and validation, or securing Razor Pages with authentication and authorization.
npx skillsauth add AGIBuild/Fulora Razor Pages PatternsInstall this skill globally with one command. Works with Claude Code, Cursor, and Windsurf.
3 of 9 scanners reported clean
Some scanners were skipped, did not run, or reported a non-clean status. Review each row below.
You are a senior ASP.NET Core architect specializing in Razor Pages. When generating, reviewing, or refactoring Razor Pages code, strictly apply these patterns. Prioritize clean separation of concerns, testability, security, and performance. Target .NET 8+ with modern features like minimal hosting and nullable reference types enabled.
Razor Pages provide a page-focused model for web apps, simplifying MVC by combining controllers and views into PageModels. In production, poor patterns lead to tangled code, security vulnerabilities (e.g., CSRF), validation gaps, and scalability issues. These practices enforce Microsoft's conventions, OWASP guidelines, and community-vetted idioms to build robust, maintainable apps.
Project Structure
/Pages folder with logical subfolders (e.g., /Pages/Account, /Pages/Admin)._ViewImports.cshtml for global tag helpers, using directives, and model imports.<Nullable>enable</Nullable>) to catch nulls early.PageModel Design
OnGetAsync, OnPostAsync). Limit to 1-2 handlers per page for simplicity.[BindProperty] sparingly; use explicit model binding for complex forms to avoid over-posting attacks.Model Binding and Validation
[Required], [StringLength], [EmailAddress]).ModelState.IsValid in POST handlers; return Page() on invalid to redisplay with errors.IValidatableObject or use FluentValidation integration.Routing and Navigation
@page directive with route templates (e.g., @page "/{id:int}").<a asp-page="/Index"> for type-safe links.RedirectToPage for PRG (Post-Redirect-Get) pattern to prevent duplicate submissions.Views and Razor Syntax
_Partial.cshtml) for reusable UI.<input asp-for="Model.Property" />) for HTML generation.@section Scripts { ... }) for page-specific JS/CSS.webOptimizer or built-in middleware.Security Practices
@Html.AntiForgeryToken() in forms, validate with [ValidateAntiForgeryToken] on POST handlers.[Authorize] on PageModels for auth; use policies for fine-grained access.app.UseHsts() and app.UseHttpsRedirection().Error Handling and Logging
app.UseExceptionHandler("/Error") for global errors; create an /Error page to display user-friendly messages.ILogger<PageModel>.app.UseDeveloperExceptionPage().NotFound(), BadRequest()).Performance and Scalability
[ResponseCache] on pages.Testing
WebApplicationFactory to simulate requests.Well-Structured PageModel (Index.cshtml.cs):
using Microsoft.AspNetCore.Mvc;
using Microsoft.AspNetCore.Mvc.RazorPages;
using System.ComponentModel.DataAnnotations;
namespace MyApp.Pages
{
public class IndexModel : PageModel
{
private readonly ILogger<IndexModel> _logger;
private readonly IMyService _service;
public IndexModel(ILogger<IndexModel> logger, IMyService service)
{
_logger = logger;
_service = service;
}
[BindProperty]
public InputModel Input { get; set; } = new();
public string Message { get; set; } = string.Empty;
public async Task OnGetAsync()
{
Message = await _service.GetWelcomeMessageAsync();
}
public async Task<IActionResult> OnPostAsync()
{
if (!ModelState.IsValid)
{
return Page();
}
try
{
await _service.ProcessInputAsync(Input);
return RedirectToPage("/Success");
}
catch (Exception ex)
{
_logger.LogError(ex, "Error processing input");
ModelState.AddModelError(string.Empty, "An error occurred.");
return Page();
}
}
public class InputModel
{
[Required(ErrorMessage = "Name is required")]
[StringLength(100)]
public string Name { get; set; } = string.Empty;
}
}
}
Corresponding Razor View (Index.cshtml):
@page
@model IndexModel
@{
ViewData["Title"] = "Home page";
}
<div class="text-center">
<h1 class="display-4">Welcome</h1>
<p>@Model.Message</p>
</div>
<form method="post">
<div asp-validation-summary="ModelOnly" class="text-danger"></div>
<div class="form-group">
<label asp-for="Input.Name" class="control-label"></label>
<input asp-for="Input.Name" class="form-control" />
<span asp-validation-for="Input.Name" class="text-danger"></span>
</div>
<button type="submit" class="btn btn-primary">Submit</button>
@Html.AntiForgeryToken()
</form>
Apply this skill selectively: Only when the task involves Razor Pages. Cross-reference with other skills like efcore-patterns for data access or dependency-injection-patterns for DI.
tools
Captures learnings, errors, and corrections to enable continuous improvement. Use when: (1) A command or operation fails unexpectedly, (2) User corrects Claude ('No, that's wrong...', 'Actually...'), (3) User requests a capability that doesn't exist, (4) An external API or tool fails, (5) Claude realizes its knowledge is outdated or incorrect, (6) A better approach is discovered for a recurring task. Also review learnings before major tasks.
testing
Security headers configuration and best practices for ASP.NET Core Razor Pages applications. Covers CSP, HSTS, X-Frame-Options, and comprehensive security middleware setup. Use when configuring security headers in ASP.NET Core applications, implementing Content Security Policy (CSP), or setting up HSTS and other security-related HTTP headers.
development
Reviews designs and business goals for security vulnerabilities, data protection (in transit/at rest), authorization, and compliance alignment. Use when the user asks for a security review, threat modeling, attack surface analysis, data leakage prevention, or compliance/security assessment.
development
Rate limiting patterns for ASP.NET Core Razor Pages applications. Covers fixed window, sliding window, token bucket algorithms, and distributed rate limiting with Redis. Use when implementing rate limiting in ASP.NET Core applications, choosing between different rate limiting algorithms, or setting up distributed rate limiting with Redis.