【问题标题】:response.redirect to another website with disclaimerresponse.redirect 到另一个带有免责声明的网站
【发布时间】:2020-09-27 12:25:02
【问题描述】:

我在我的网站中创建了一个简单的页面,用于计算这些成员在论坛中发送的超链接的传出点击次数。我将以blah开头的链接转换为linkout.asp?u=blah,这是linkout.asp的来源

<%
url=request("u")
response.redirect url
%>

但是,验证器和 Google 分析会警告我这些外部网站上发生的 404 或 500 错误。这些目标页面似乎是我自己网站的一部分,这些错误被视为内部错误。使用response.redirect强调那些目标页面不是我自己的正确方法是什么?

【问题讨论】:

  • Response.Redirect 执行“302 对象已移动”标头重定向,如果 Google Analytics(分析)报告错误,那是因为您的重定向代码存在问题,并且返回的是错误而不是执行重定向。您提供的示例代码正在重定向到一个不存在的变量。你应该重定向到url,而不是u
  • 谢谢。我已经更新了这个问题。在这里写问题而不是在我的真实代码中时,变量 u 是错字。 @亚当
  • 据我所知,Google Analytics 只会记录运行分析 JS 的域上生成的错误代码,这意味着它仍然是您的代码的问题。您是否在重定向之前使用正则表达式来验证 URL?还是您也使用 linkout.asp 来执行内部重定向?

标签: asp-classic response.redirect


【解决方案1】:

您可以尝试客户端重定向。

例如,这样的事情应该让您有机会感谢访问者,提出免责声明,并为禁用 JavaScript 的用户提供访问外部网站的方法,并希望阻止 Google Analytics 的恶果...

<html>
<head>
<meta http-equiv="refresh" content="3;url=<%= request("u") %>" />
<title>Redirecting...</title>
<script type="text/javascript">
var tmr = null;
function doRedirect() {
    window.location.href = '<%= request("u") %>';
}
window.onload = function() {
    tmr = window.setTimeout(doRedirect, 3000);
}
window.onunload = function() {
    window.clearTimeout(tmr);
    tmr = null;
}
</script>
</head>
<body>
<p>Thank you for visiting our site.  You will be redirected to <%= request("u") %> in 3 seconds</p>
<p>We take no responsiblity for the content displayed on external sites.</p>
<noscript>
<p>If you are not redirected, please <a href="<%= request("u") %>">click here</a> to navigate to the site.</p>
</script>
</body>
</html>

请注意:上述代码不应在生产环境中使用,因为request("u") 在使用前未经验证或清理。请在依赖所有输入参数之前采取额外的预防措施。

希望这会有所帮助。

【讨论】:

  • 当您可以使用 &lt;meta http-eqiv="refresh" content="3"&gt;a combination of both 时,为什么还要使用 JavaScript。
  • 啊,好点子。我的疏忽。 &lt;meta&gt; 标签+注释已添加。谢谢 Lankymart。
猜你喜欢
  • 2017-12-05
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2021-01-11
相关资源
最近更新 更多