如何更改具有特定域名的localhost?

时间:2013-04-12 06:07:09

标签: c# asp.net

我正在检查任何域名的链接是否链接正常工作。但是当我从localhost调试时,我不能使用特定的域名,例如localhost:xyz/preferences?hl=en而不是我想要的{{3}我们可以通过替换字符串

来做
var linkWithLocalHost = "http://localhos:234/foo"; 

var result = // ??? some code that manipulates linkWithLocalHost 
// expecting "http://google.co.il/foo" as result

2 个答案:

答案 0 :(得分:0)

再一次随机猜测(因为我可能会过度简化要求)。

要操纵网址,请使用相应的课程UriUriBuilder

var linkWithLocalHost = "http://localhos:234/foo"; 
// expecting "http://google.co.il/foo" as result

var builder  = new UriBuilder(linkWithLocalHost);
builder.Host = "google.co.il";
builder.Port = 80;
var result = builder.Uri.ToString();

对标题中的问题的回答是:

  • 使用hosts文件(如果使用IIS作为服务器)
  • 使用Fiddler重新映射域名(适用于VS Web服务器或IIS或任何其他服务器)

答案 1 :(得分:0)

您可以使用C:\ Windows \ System32 \ drivers \ etc \ hosts文件。在文件中有说明,说明如何使用它。

例如,我在此文件中附加了一个新行:

127.0.0.1 mywebsite # for stackoverflow question

现在当我将http://mywebsite/写入浏览器的地址栏时,我会看到通常在撰写http://localhost/时会看到的页面。