2012-09-03 123 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
相關問題