-
Notifications
You must be signed in to change notification settings - Fork 10.5k
Closed
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsquestion
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
I need to read the HTTP headers from inside a Blazor Web component.
When using the IHttpContextAccessor, the headers are not returned even though the headers exist in all the HTTP responses.
How can I use the HTTP headers returned in the client responses when using Blazor Web?
Expected Behavior
All headers from the HTTP response should be present in the IHttpContextAccessor
@inject IHostEnvironment Env
@inject IHttpContextAccessor HttpContextAccessor
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<base href="/" />
<link rel="stylesheet" href="css/bootstrap/bootstrap.min.css" />
<link href="css/site.css" rel="stylesheet" />
<link href="BlazorWebFromBlazorServerOidc.styles.css" rel="stylesheet" />
<HeadOutlet @rendermode="InteractiveServer" />
</head>
<body>
<Routes @rendermode="InteractiveServer" />
<script nonce="@GetNonce()" src="_framework/blazor.web.js"></script>
</body>
</html>
@code {
private string GetNonce()
{
var nonce = string.Empty;
Microsoft.Extensions.Primitives.StringValues nonces;
var found = HttpContextAccessor.HttpContext!.Response.Headers.TryGetValue("Content-Security-Policy", out nonces);
if(found)
{
nonce = nonces.First();
};
return nonce!;
}
}
.NET Version
8
Anything else?
Blazor Web (Server)
edcsu and veikkoeeva
Metadata
Metadata
Assignees
Labels
✔️ Resolution: AnsweredResolved because the question asked by the original author has been answered.Resolved because the question asked by the original author has been answered.Status: Resolvedarea-blazorIncludes: Blazor, Razor ComponentsIncludes: Blazor, Razor Componentsquestion