gpt4 book ai didi

javascript - 如何使用 React 应用程序将 ASP.NET Core Controller 操作 View 之一访问到 iframe 中?

转载 作者:行者123 更新时间:2023-11-28 03:37:09 27 4
gpt4 key购买 nike

当我尝试从React应用程序访问asp.net core应用程序 Controller View 之一时,在浏览器控制台中我遇到了类似的错误

'拒绝在框架中显示'http://localhost:1212/Account/Login/?ReturnUrl=%Home%MyIFrame%3url%TestData',因为它将'X-Frame-Options'设置为'同源'.'

因为我用 [Authorize] 属性装饰了操作方法

startup.cs文件中包含

Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory){
app.UseCors(
options => options
.WithOrigins(
"http://localhost:3000",
)
.AllowAnyMethod()
.AllowAnyHeader()
);
}

最佳答案

X-FRAME-OPTIONS 是一个 Web header ,可用于允许或拒绝将页面嵌入 iframe。这在防范 clickjacking 时非常重要尝试。

我认为不建议这样做,但是如果您想更改使您的应用程序成为 iframe,您可以尝试在 ASP.NET Core 应用程序的 Configure 功能中添加以下配置来设置 X-Frame-Options响应头,例如:

app.Use(async (context, next) =>
{
context.Response.Headers.Add("X-Frame-Options", "AllowAll");
await next();
});
app.UseMvc();

关于javascript - 如何使用 React 应用程序将 ASP.NET Core Controller 操作 View 之一访问到 iframe 中?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57606991/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com