Request Migration

This sample demonstrates the RequestShim that provides Web Forms-compatible Request.QueryString, Request.Url, and Request.Cookies access in Blazor. The shim falls back to NavigationManager when HttpContext is unavailable (interactive mode).


1. Request.QueryString

Access query string parameters using the same dictionary-style syntax as Web Forms. The shim falls back to parsing from NavigationManager.Uri in interactive mode.

Before (Web Forms)

string name = Request.QueryString["name"];
string id = Request.QueryString["id"];

After (Blazor with BWFC)

// Same code works!
string name = Request.QueryString["name"];
string id = Request.QueryString["id"];
Live Demo - QueryString

Try navigating to: /migration/request?name=test&id=42

Request.QueryString["name"]: test

Request.QueryString["id"]: 42


2. Request.Url

Access the full request URL. Falls back to NavigationManager.Uri in interactive mode.

Live Demo - Request.Url

Current URL: http://blazorwebformscomponents.azurewebsites.net/migration/request?id=42&name=test


3. Request.Cookies (with SSR Guard)

Cookies require HttpContext and are only available during SSR/pre-render. In interactive mode, Request.Cookies returns an empty collection. Use the IsHttpContextAvailable guard pattern.

Before (Web Forms)

string theme = Request.Cookies["theme"]?.Value;

After (Blazor with BWFC)

// Guard for HttpContext availability
if (IsHttpContextAvailable)
{
    var theme = Request.Cookies["theme"];
}
Live Demo - Cookies

IsHttpContextAvailable: True

HttpContext is available — cookies can be read from the HTTP request.