【问题标题】:IIS: How to redirect all subpages to other domain, but not the root domainIIS:如何将所有子页面重定向到其他域,而不是根域
【发布时间】:2015-01-16 08:26:44
【问题描述】:

我对 IIS 或 web.config 中的重定向有疑问。

我有两个域:

domain1.com 和 domain2.com

当人们浏览http://domain1.com 时,他们会登陆该域。但是,如果他们浏览到 domain1.com 上的任何子页面,他们将被重定向到 domain2.com 上的同一子页面。 假设我去 domain1.com/my-subpage 我想将人们重定向到 domain2.com/my-subpage

这意味着人们登陆并停留在 domain1.com 域的唯一时间是当他们直接登陆域的根目录时。在对 domain1.com/* 的所有其他请求中,它们被重定向到 domain2.com/*

如果整个域(包括首页)应该重定向,我知道如何在 IIS 中使用重定向模块执行此操作。但是当首页不应重定向时,我想不出有什么办法可以解决这个问题。

希望有人可以帮助我。

提前致谢。

问候, 金

【问题讨论】:

    标签: asp.net redirect iis web-config


    【解决方案1】:

    一种方法是在Global.asaxApplication_BeginRequest 下进行重定向,这是一个示例:

    protected void Application_BeginRequest(Object sender, EventArgs e)
    {   
        // this is an example, change it base on your case..
        if(!HttpContext.Current.Request.Path.Contain("www.domain1.com/"))
           HttpContext.Current.Response.Redirect(
              Request.RawUrl.Replace("www.domain1.com/","www.domain2.com/")
                 , true);   
    }
    

    这不适用于回发。

    第二种方式,也适用于回发,并且可以为您工作,因为您只有一个页面并且所有其余链接都重定向到内页是更改default.aspx页面上的<form action=""....>,第一个所有页面。

    在回发时,您可能在对 asp.net 表单进行安全检查时遇到问题,您必须检查一下。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2016-01-18
      • 1970-01-01
      • 1970-01-01
      • 2018-03-11
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多