将外部 URL 重定向到退出页面

发布于 2024-10-14 06:12:00 字数 129 浏览 6 评论 0原文

将请求外部 URL 的用户重定向到某种告别页面的最佳方法是什么?

我知道我可以努力安装某种类似 mod_rewrite 的模块。但我不能在 global.asax 或母版页中执行某种 Page_OnRequest 类型的函数吗?

What would be the best way to redirect users who request an external URL, to a sort of good-bye page?

I know I could work hard to install some sort of mod_rewrite-like module. But can't I do some sort of Page_OnRequest type function in global.asax or the master pages?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

醉生梦死 2024-10-21 06:12:00

您可以让这些 url 实际上指向您自己网站上的重定向页面,然后再将它们转发到最终目的地:

<a href="redirect.aspx?url=stackoverflow.com">Stack Overflow</a>

然后您可以对重定向执行任何您想要的操作,并且可以进行重定向,以便重定向隐藏 url,对其进行编码、添加参数等

You could have these urls actually point to a redirection page on your own site before forwarding them on to the ultimate destination:

<a href="redirect.aspx?url=stackoverflow.com">Stack Overflow</a>

Then you could do whatever you wanted with the redirection, and it could be worked so that the redirection hid the url, encoded it, added parameters, etc.

别念他 2024-10-21 06:12:00

最简单的方法是使用 jQuery 挂钩页面上所有标签上的单击事件:

$(function(){

  $('a').click(function(e){
    var proceed       = true ;
    var anchor        = $(this) ;
    var href          = anchor.attr('href') ;
    var isExternalUrl = CheckForExternalUrl( href ) ;

    if ( isExternalUrl )
    {
      e.PreventDefault() ;
      window.location = "outside_link.aspx?url=" + href ;
      proceed         = false ;
    }
    return proceed ;
  }) ;
}) ;

任何被单击的链接都会触发事件处理程序。外部 URL 将导致页面 Outside_link.aspx 加载查询字符串中的目标 URL。内部 URL 将正常运行。

简单的。

Easiest way is to use jQuery to hook the click event on all the tags on the page:

$(function(){

  $('a').click(function(e){
    var proceed       = true ;
    var anchor        = $(this) ;
    var href          = anchor.attr('href') ;
    var isExternalUrl = CheckForExternalUrl( href ) ;

    if ( isExternalUrl )
    {
      e.PreventDefault() ;
      window.location = "outside_link.aspx?url=" + href ;
      proceed         = false ;
    }
    return proceed ;
  }) ;
}) ;

Any link that gets clicked fires the event handler. External URLs will cause the page outside_link.aspx to loaded with the destination url in the query string. Internal URLs will behave normally.

Simple.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文