Skip to content

Instantly share code, notes, and snippets.

@ADefWebserver
Created April 1, 2025 12:56
Show Gist options
  • Save ADefWebserver/74a8d483b3af21359d85e943d2d023a0 to your computer and use it in GitHub Desktop.
Save ADefWebserver/74a8d483b3af21359d85e943d2d023a0 to your computer and use it in GitHub Desktop.
Allow a Blazor App app to be iframed in another app
// Configure the HTTP request pipeline
// To allow this Blazor App app to be iframed in another app
app.Use(async (context, next) =>
{
// How to display the app in an iframe
context.Response.OnStarting(() =>
{
// Remove X-Frame-Options header
context.Response.Headers.Remove("X-Frame-Options");
// Remove Content-Security-Policy header
context.Response.Headers.Remove("Content-Security-Policy");
// Add custom CSP to allow iframing from anywhere
context.Response.Headers.Append("Content-Security-Policy",
"default-src 'self'; " +
"script-src 'self'; " +
"style-src 'self' 'unsafe-inline'; " +
"img-src 'self' data:; " +
"font-src 'self'; " +
"frame-ancestors *;");
return Task.CompletedTask;
});
await next();
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment