Other 1xx codes
All HTTP status codes in ASP.NET Core
1xx Informational
The server agrees to switch protocols as the client asked in its Upgrade header, most often to WebSocket.
In ASP.NET Core: ASP.NET Core sends it when you call AcceptWebSocketAsync() on a WebSocket request.
The StatusCodes constant, HttpStatusCode enum name, reason phrase, class, and how EnsureSuccessStatusCode() and the standard resilience handler treat 101.
| Constant | StatusCodes.Status101SwitchingProtocols |
|---|---|
| HttpStatusCode | HttpStatusCode.SwitchingProtocols |
| Reason phrase | Kestrel sends Switching Protocols |
| Class | 1xx, informational |
| IsSuccessStatusCode | false |
| EnsureSuccessStatusCode() | throws HttpRequestException: Response status code does not indicate success: 101 (Switching Protocols). |
| Standard resilience handler | does not retry it |
ASP.NET Core sends it when you call AcceptWebSocketAsync() on a WebSocket request.
Setup
app.UseWebSockets();
app.Map("/ws", async (HttpContext ctx) =>
{
if (!ctx.WebSockets.IsWebSocketRequest) { ctx.Response.StatusCode = 400; return; }
using var socket = await ctx.WebSockets.AcceptWebSocketAsync();
});Request
GET /ws HTTP/1.1
Upgrade: websocket
Connection: Upgrade
Sec-WebSocket-Key: dGhlIHNhbXBsZSBub25jZQ==
Sec-WebSocket-Version: 13Response (recorded)
HTTP/1.1 101 Switching ProtocolsAcceptWebSocketAsync() sends 101 Switching Protocols; after that the connection is a WebSocket.
Every response on this page was recorded from ASP.NET Core 10.0.12 on Kestrel in the Production environment; the HttpClient rows come from .NET 10.0.12 and Microsoft.Extensions.Http.Resilience 10.10.0.
All HTTP status codes in ASP.NET Core