c# - 如何判断您的页面是否在 .Net 中的 iFrame 中运行?

标签 c# .net html iframe

<分区>

我有一个 ASPX 页面,有时会加载到我的应用程序中的 iFrame 中,有时不会。从背后的代码中,您如何检测您的页面是否是从 iFrame 加载的。

最佳答案

我真的怀疑你能否从后面的代码中做到这一点。您可能可以在 JavaScript 中执行此操作,但不能从后面的代码中执行。

如果你真的需要从后面的代码中知道,你可能会在 iframe 中加载页面时提供一个查询字符串参数?像...

<iframe src ="page.aspx?iframe=true" width="100%" height="300">
</iframe>

然后在后面的代码中你可以做类似...

// sometimes my Asp.NET, Java and PHP get a little confused
// so maybe this might throw some no such index type errors,
// but I think it communicates the idea
string iframe = Request.QueryString["iframe"];
if(!string.IsNullOrEmpty(iframe) && iframe.Equals("true"))    {
    // this page is in the iframe
}

关于c# - 如何判断您的页面是否在 .Net 中的 iFrame 中运行?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2730516/

相关文章:

.net - 如何在无法访问 System.Windows.Forms.PaintEventArgs 命名空间的情况下在 Winform 上绘图?

html - 垂直居中单个和多词链接

javascript - 从下拉列表中获取选定的文本,但使用 jQuery 删除数值

c# - 您如何使该switch语句尽可能快?

c# - 属性可以引用嵌入式资源吗?

c# - 数据库优先 Entity Framework 将唯一外键映射为一对多

c# - 用 OLEDB 读取 Excel 文件?

.net - 如何将参数传递给外部 (SQLCLR) SQL Server 触发器

c# - 我们的 C# 类成员有多少(多少) 'private'?

html - 表剥离不起作用?