Skip to content

GWP Minimal API and Razor Pages hosting samples#172

Open
alafleur-genetec wants to merge 6 commits intomainfrom
feat/gwp-web-samples
Open

GWP Minimal API and Razor Pages hosting samples#172
alafleur-genetec wants to merge 6 commits intomainfrom
feat/gwp-web-samples

Conversation

@alafleur-genetec
Copy link
Copy Markdown
Member

No description provided.

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.
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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/config and /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.

Comment on lines +47 to +52
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:");
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
Comment on lines +54 to +63
### 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>
Copy link

Copilot AI Apr 2, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Copilot uses AI. Check for mistakes.
alafleur-genetec and others added 4 commits April 2, 2026 16:56
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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

2 participants