简体   繁体   English

不通过iframe访问而不使用JavaScript时从页面重定向?

[英]Redirecting from a page when not accessed via an iframe without using JavaScript?

I need to redirect users if they try and access certain pages directly, ie not via the iframe I've provided. 我需要重定向用户,如果他们尝试直接访问某些页面,即不通过我提供的iframe。 This is to stop them accessing other users' areas. 这是为了阻止他们访问其他用户的区域。

All the solutions I've found (which work, btw) use JavaScript - the current working script I have is 我找到的所有解决方案(哪个工作,顺便说一句)都使用JavaScript - 我目前使用的工作脚本是

if (top == self) {
var newURL = 'http://www.exampleurlhere.co.uk/'
window.setTimeout('GotoIndex()',0);
}
function GotoIndex() { top.location.href = newURL; }

However, this will of course only work if the user has JavaScript enabled, which kind of scuppers me. 但是,这当然只有在用户启用了JavaScript时才会起作用,这种情况会让我感到不安。 Is there a way to achieve this server-side? 有没有办法实现这个服务器端? I'm using aspx. 我正在使用aspx。

Thanks, Oli. 谢谢,奥利。

You can't check it severside as IFrame requests (in general) are no different from any other HTTP request. 由于IFrame请求(通常)与任何其他HTTP请求没有区别,因此您无法在其中进行检查。 You can however use a GET parameter to indicate this is an IFrame 但是,您可以使用GET参数来指示这是一个IFrame

<iframe src="mypage?iframe=yes"></iframe>

Obviously this solution will only work if you're in control of the code that contains the IFrame, otherwise there is no way to do it server-side. 显然,只有在您控制包含IFrame的代码时,此解决方案才有效,否则无法在服务器端执行此操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM