如何强制页面仅在IFrame中加载?

thi*_*eek 2 iframe webpage http

我有一组asp.net页面,我希望它们只能在从IFrame加载时才能访问或加载.如果尝试直接通过浏览器地址栏访问页面,则根本不应显示该页面或向用户显示该消息.

我尝试使用cookie和sesions,但它们并不是那么有效,因为一旦创建cookie /会话,您可以直接从浏览器访问页面,绕过IFrame.

我的开发平台是asp.net 2.0 +,vs2008,C#2.0+

You*_*Ken 5

这是将脚本放在head标签中的几次之一的示例.

<html>
<head>
    <title>sandBox</title>
    <script type="text/javascript">
        if (frameElement == null) {
            //change location or close
            window.location = "http://stackoverflow.com";
            // or window.close();
        }
    </script>
</head>
<body>
content goes here
</body>
</html>
Run Code Online (Sandbox Code Playgroud)