Authorization and exports

Why a route that requires authorization stops the export, and how to exclude it, publish it anyway, or allow anonymous access.

On this page
Program.cscsharp
app.MapStatic<AdminPage>("/admin", (ISiteData d) => d.Reports)
   .RequireAuthorization()
   .ExcludeFromStaticExport();   // served live only

Conventions such as RequireAuthorization() apply to the live app. They cannot travel with a static file. If a mapped route requires authorization, the export stops and lists the route:

text
Static export refused: 1 route(s) require authorization on the live app, and static files cannot enforce it:
  - /admin/{Id}
Nothing was written.

Pick one fix

Call Effect
.ExcludeFromStaticExport() Not exported. Still served live.
.AllowStaticExport() Exported anyway, so the file is public.
.AllowAnonymous() The route is public. Nothing to protect.
csharp
app.MapStatic<AdminPage>("/admin", ...).RequireAuthorization().ExcludeFromStaticExport(); // live only
app.MapStatic<PrivatePage>("/members", ...).RequireAuthorization().AllowStaticExport();   // exported, so public
app.MapStatic<DraftPage>("/draft").ExcludeFromStaticExport();

You can set these on a single endpoint or on a MapGroup.

What an excluded route means

  • Bevel leaves excluded routes out of BevelEndpointRegistry.GetAllRoutesAsync. GetRoutesAsync lists them with IsExported = false.
  • Linking to an excluded route from an exported page fails the export. Static pages cannot point at a page that is not in the site.
  • In your app, excluded routes always run live, in every environment.
  • The sitemap built by MapSitemap skips excluded routes.

Conventions apply to all endpoints a MapStatic* call creates: the main route, the .html or index.html alias, and the paged first-page route.

Static files in wwwroot Since 0.3

A route like /{Section}/{Slug} can match the URL of a file in wwwroot, such as /css/site.css. Bevel decides who wins:

  • Guarded routes win. If the route has an access guard, Bevel keeps hiding the same-URL file. Authorization, a fallback policy, an endpoint filter or group filter, CORS and rate limiting all count. UseStaticFiles() cannot serve the file around the guard.
  • Unguarded routes yield. If the route has no guard, an existing file in wwwroot is served as a normal static file.
  • Literal routes always win. /rss.xml hides a file at /rss.xml, guarded or not.