嗨我正在開發網站使用asp .net mvc5,但是當我使用IFrame它沒有顯示任何結果。谷歌搜索和閱讀一些文件後,我發現MVC5默認停止Iframe。我在stackoverflow和其他博客上找到了一些答案,但沒有爲我工作。請檢查在那裏我做的錯誤:Iframe沒有顯示網站的Asp .Net MVC5
這裏是我的代碼:
public ActionResult Index()
{
return View();
}
筆者認爲:
<iframe width="482" height="500" scrolling="no" frameborder="0" id="paymentFrame" src="http://www.codingfusion.com"></iframe>
我已經試過以下至今的解決方案:
After update to MVC 5, iframe no longer works
https://www.iambacon.co.uk/blog/mvc5-prevents-your-website-being-loaded-in-an-iframe
http://joost.haneveer.nl/asp-net/display-mvc-5-web-site-in-an-iframe/
這裏是我的Global.asax文件:
protected void Application_Start()
{
AreaRegistration.RegisterAllAreas();
FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters);
RouteConfig.RegisterRoutes(RouteTable.Routes);
BundleConfig.RegisterBundles(BundleTable.Bundles);
// MVC5 generates the "X-Frame-Options SAMEORIGIN" header by default, the following line disables the default behaviour
System.Web.Helpers.AntiForgeryConfig.SuppressXFrameOptionsHeader = true;
}
protected void Application_BeginRequest()
{
Response.AddHeader("X-Frame-Options", "DENY");
}
謝謝,但它不工作,我也試着刪除的Application_BeginRequest() –