GWP Minimal API and Razor Pages hosting samples#172
GWP Minimal API and Razor Pages hosting samples#172alafleur-genetec wants to merge 6 commits intomainfrom
Conversation
Two ASP.NET Core samples demonstrating server-side token proxy patterns for hosting the Genetec Web Player: - GwpMinimalApiSample: single Program.cs with static HTML page - GwpRazorPagesSample: Razor Pages with per-request CSP nonces and server-rendered configuration via JsonSerializer.Serialize Both samples include proper player lifecycle cleanup on failed start and cancellable startup with generation tracking.
The limitation is that the application itself has no user authentication, not just the token endpoint.
There was a problem hiding this comment.
Pull request overview
Adds two new ASP.NET Core hosting samples for Genetec Web Player (GWP): a Minimal API static-site sample and a Razor Pages sample that demonstrates per-request CSP nonces while proxying Media Gateway token requests server-side.
Changes:
- Introduces GwpMinimalApiSample (static
index.html+/api/configand/api/token/{cameraId}endpoints). - Introduces GwpRazorPagesSample (Razor page with server-rendered config + CSP nonce middleware +
/api/token/{cameraId}endpoint). - Adds sample documentation and local debug profiles (
launchSettings.json) for both.
Reviewed changes
Copilot reviewed 13 out of 13 changed files in this pull request and generated 7 comments.
Show a summary per file
| File | Description |
|---|---|
| Samples/Genetec Web Player/GwpRazorPagesSample/README.md | Documents the Razor Pages hosting approach, CSP nonce flow, and environment requirements. |
| Samples/Genetec Web Player/GwpRazorPagesSample/Properties/launchSettings.json | Adds local debug profile and ports for the Razor Pages sample. |
| Samples/Genetec Web Player/GwpRazorPagesSample/Program.cs | Implements CSP nonce middleware, Media Gateway HttpClient, Razor Pages hosting, and token proxy endpoint. |
| Samples/Genetec Web Player/GwpRazorPagesSample/Pages/Index.cshtml.cs | Supplies server-rendered config and CSP nonce to the Razor page. |
| Samples/Genetec Web Player/GwpRazorPagesSample/Pages/Index.cshtml | Provides the GWP UI and client logic (including dynamic gwp.js loading). |
| Samples/Genetec Web Player/GwpRazorPagesSample/GwpRazorPagesSample.csproj | Adds new net8.0 Razor Pages sample project. |
| Samples/Genetec Web Player/GwpRazorPagesSample/appsettings.json | Adds Media Gateway configuration for the Razor Pages sample. |
| Samples/Genetec Web Player/GwpMinimalApiSample/wwwroot/index.html | Provides the Minimal API sample UI and client logic, including CSP via meta tag. |
| Samples/Genetec Web Player/GwpMinimalApiSample/README.md | Documents the Minimal API hosting approach and environment requirements. |
| Samples/Genetec Web Player/GwpMinimalApiSample/Properties/launchSettings.json | Adds local debug profile and ports for the Minimal API sample. |
| Samples/Genetec Web Player/GwpMinimalApiSample/Program.cs | Implements Minimal API hosting, Media Gateway HttpClient, config endpoint, and token proxy endpoint. |
| Samples/Genetec Web Player/GwpMinimalApiSample/GwpMinimalApiSample.csproj | Adds new net8.0 Minimal API sample project. |
| Samples/Genetec Web Player/GwpMinimalApiSample/appsettings.json | Adds Media Gateway configuration for the Minimal API sample. |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| context.Response.Headers["Content-Security-Policy"] = string.Join("; ", | ||
| "default-src 'self' https:", | ||
| $"script-src 'self' https: 'nonce-{nonce}'", | ||
| $"style-src 'self' 'nonce-{nonce}'", | ||
| "connect-src 'self' https: wss:", | ||
| "media-src https: blob:"); |
There was a problem hiding this comment.
The CSP policy allows https: in default-src and script-src, which permits scripts (and other resources via default-src) to load from any HTTPS origin. If the goal is to tighten CSP, consider restricting sources to the configured Media Gateway origin (and/or setting a nonce on the dynamically injected gwp.js script) instead of using the broad scheme source.
| ### 2. Allow the page origin in Media Gateway CORS | ||
|
|
||
| If strict CORS is enabled, add the ASP.NET application origin to `MediaGateway.gconfig`: | ||
|
|
||
| ```xml | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <Configuration> | ||
| <MediaGateway EnforceStrictCrossOrigin="true"> | ||
| <AllowedOrigin Origin="https://localhost:5001" /> | ||
| </MediaGateway> |
There was a problem hiding this comment.
The CORS example hard-codes https://localhost:5001, but this sample’s launchSettings.json uses different default ports. Consider updating the snippet/text to tell readers to use the actual origin printed on the page/console output (or match the configured applicationUrl) to avoid confusion.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
No description provided.