ASP.NET Core Razor Server Demo
The ASP.NET Core Razor Server Demo provides the same streaming functionality as the .NET Server Demo — multi-protocol ingest and delivery, publishing points, media processing, recording, and all standalone samples — but integrated into the ASP.NET Core infrastructure. This enables hosting the streaming server alongside Razor Pages, MVC controllers, middleware, and other ASP.NET Core services within a single application.
Additionally, this demo initializes a WebTransport server and includes a WebTransport playback page (wt.html). WebTransport is available on Kestrel only.
Project Structure
The project contains the same sample classes as the .NET Server Demo:
| Class | Description |
|---|---|
MultiProtoServer |
Multi-protocol streaming server (RTMP, RTSP, SRT, HLS, MPEG-DASH, WebRTC, WebTransport) |
SimpleRtmpServer |
Stand-alone RTMP server with manual media flow |
SimpleRtspServer |
Stand-alone RTSP server with manual media flow |
SimpleWebRtcServer |
Stand-alone WebRTC signaling server |
SendSample1 / SendSample2 |
Send pre-encoded media to a remote server |
ReceiveSample |
Receive and decode media from a remote source |
FileReaderSample |
Read and decode MP4 files |
FileWriterSample |
Record streams to MP4 files |
IsoFragmentWriterSample |
Generate fragmented MP4 segments |
For detailed documentation of each sample, see the corresponding pages under .NET Server Demo.
ASP.NET Core Integration
Application Setup
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddControllers();
builder.Services.AddRazorPages();
var app = builder.Build();
app.Use(async (context, next) =>
{
context.Response.Headers.Append("Cross-Origin-Embedder-Policy", "require-corp");
context.Response.Headers.Append("Cross-Origin-Opener-Policy", "same-origin");
await next();
});
app.UseStaticFiles();
app.UseRouting().UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapRazorPages();
});
app.UseWebSockets(new WebSocketOptions());
The application configures Razor Pages, MVC controllers, static files, and WebSocket support. COOP/COEP headers are added via middleware for cross-origin isolation, which is required by some browser APIs (e.g., SharedArrayBuffer used in WebTransport playback).
HTTP Request Dispatching
app.Run(async (context) =>
{
await sample.HttpDispatcher.DispatchRequest(
new VAST.HTTP.AspHttpRequestContext(context));
});
HTTP requests not handled by ASP.NET Core (Razor Pages, controllers, static files) are dispatched to the VASTreaming engine via HttpDispatcher. This allows HLS, MPEG-DASH, WebRTC signaling, WebTransport, JSON API, and other HTTP-based protocols to be served through the same Kestrel or IIS pipeline.
The dispatching approach shown above is just an example. You can implement your own dispatching scenarios based on ASP.NET Core routing, middleware branching, path matching, or any other logic to control which requests are forwarded to the streaming engine.
The HttpDispatcher is created with the AspNetCore type:
this.HttpDispatcher = new VAST.HTTP.HttpServer(
VAST.HTTP.HttpServer.Type.AspNetCore, null, 8888, 0);
server.Start(this.HttpDispatcher);
Hosting Options
The demo supports both Kestrel and IIS hosting, controlled via the VAST_HTTP_SERVER environment variable:
Kestrel
if (Environment.GetEnvironmentVariable("VAST_HTTP_SERVER") == "Kestrel")
{
builder.WebHost.UseKestrel(options =>
{
options.AllowSynchronousIO = true;
options.Listen(System.Net.IPAddress.Any, 8888);
});
}
For HTTPS with HTTP/3 support (required for WebTransport):
options.Listen(System.Net.IPAddress.Any, 8443, listenOptions =>
{
listenOptions.UseHttps(certificate);
listenOptions.Protocols = HttpProtocols.Http1AndHttp2AndHttp3;
});
IIS
if (Environment.GetEnvironmentVariable("VAST_HTTP_SERVER") == "IIS")
{
builder.Services.Configure<IISServerOptions>(options =>
{
options.AllowSynchronousIO = true;
});
}
AllowSynchronousIO must be enabled for both Kestrel and IIS as the streaming engine requires synchronous I/O operations.
WebTransport
The MultiProtoServer in this demo enables a WebTransport server for low-latency media delivery over HTTP/3:
server.EnableWebTransport = true;
server.WebTransportServerParameters = new VAST.HTTP.WebTransportServerParameters
{
WebTransportPath = "/wt",
};
WebTransport requires .NET 9 or later and is available on Kestrel only. A TLS certificate must be configured with HTTP/3 enabled on the HTTPS endpoint.
The demo includes a WebTransport playback page (wt.html) with supporting JavaScript files in the wwwroot folder. The page connects to the WebTransport endpoint and renders video and audio using browser APIs.
Razor Pages
The demo includes an Index.cshtml Razor page that serves as the landing page:
public class IndexModel : PageModel
{
[FromQuery(Name = "DisplayText")]
public string DisplayText { get; set; } = "Hello World";
public void OnGet()
{
Program.DisplayText = this.DisplayText;
}
}
The page displays server status information and links to the HLS and WebTransport playback pages. The DisplayText query parameter can be used to change the overlay text rendered on the video stream (when push sources 2 or 3 are enabled).
API Controller
The demo includes an ASP.NET Core API controller for changing the display text:
[ApiController]
[Route("/siteApi/v1/displayText")]
public class SiteApiController : ControllerBase
{
[HttpGet]
public async Task<IActionResult> IndexAsync([FromQuery] string text)
{
Program.DisplayText = text;
return Ok();
}
}
This demonstrates how ASP.NET Core controllers and the VASTreaming engine coexist — the controller handles /siteApi/v1/displayText while all other unmatched requests are dispatched to the streaming engine.
Setup
Set the license key in
Program.cs:VAST.Common.License.Key = "YOUR_LICENSE_KEY";Set the
VAST_HTTP_SERVERenvironment variable toKestrelorIISFor WebTransport, configure a TLS certificate and enable the HTTPS endpoint with HTTP/3
Run the application
See Also
- Sample Applications — overview of all demo projects
- .NET Server Demo — detailed documentation for all sample classes
- VAST.Network Library — StreamingServer API reference