2012-09-03 125 views
2

我想在Windows 2008 R2服务器上做一些测试。也就是说,让一个URL重定向到localhost如何将URL重定向到本地主机?

例如,让"http://mysample.mydomain.com/index.html"实际访问“http://localhost/index.html”。有什么办法可以做到这一点?

我试图编辑windows\system32\drivers\etc\hosts文件,添加127.0.0.1 -> mysample.mydomain.com映射,但它不起作用。看起来127.0.0.1localhost是不一样的。 我可以访问“http://localhost/index.html”,但我无法访问“http://127.0.0.1/index.html”!

在此先感谢!

+0

我认为这应该被迁移到superuser.com –

回答

0

是继承自System.Web.UI.Page然后负载重载写类:

public abstract class CorePage : Page 
{ 
    protected override void OnLoad(EventArgs e) 
    { 
     base.OnLoad(e); 

     //TODO: check request url and make a redirect if required! 

    } 
} 

更改所有的网页都从CorePage和工作继承完成!这当然只适用于应用程序级别的aspx页面,而不适用于整个IIS。

+0

我想用我的IE浏览器来做到这一点。 – quantity

0

由于您在Windows 2008 R2服务器上,我猜测您正在使用IIS进行测试。另外请注意,Windows Server 2008是默认情况下“启用”IPv6的第一个Windows版本 - 但您的IPv4版本是否也启用了?

Enable IPv4: [Control panel > Network and sharing center > Change adapter settings > Right click the adapter used for connectivity and select properties > See if IPv4 is checked. ] 

我认为你的localhost在内部被解析为使用:: 1(IPv6)环回地址。您可以通过检查确认:

对于IPv6测试:ping localhost -6和IPv4测试:ping localhost -4。如果它解析为:: 1,则它使用IPv6地址。

你\等\ hosts文件应具有以下条目:

::1 locahost mysample.mydomain.com 

现在做一个ping测试,ping mysample.mydomain.com -6。这应该确认mysample.mydomain.com已被解析为使用IPv6的本地环回 地址。

参见:

  1. Difference-between-127-0-0-1-and-localhost
  2. Localhost
相关问题