根据服务器切换域名? [英] Switching Domain name depending on server?

查看:57
本文介绍了根据服务器切换域名?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用两个测试服务器和一个生产。我有一个实用工具类

,其中包含通过该网站使用的许多链接。此类中的一个

变量被分配了域名。我需要

根据我正在使用的服务器自动设置这个值。

域名可以类似于以下任何一个,具体取决于服务器:


- abc.com

- 190.168。 2.100

- 190.168.2.109


最好的方法是什么?


谢谢,

Brett

I use two test servers and one production. I have a Utilities class
that holds many of the links used through the site. One of the
variables in this class is assigned the domain name. I need to
automatically set this value depending on the server I''m on. The
domain can be similar to any of the following depending on the server:

- abc.com
- 190.168.2.100
- 190.168.2.109

What is the best way to do that?

Thanks,
Brett

推荐答案

Brett,


为什么不使用主机文件?它位于这里...


C:\ WINDOWS \ system32 \ drivers \ etcc \hosts


它看起来像这样。


127.0.0.1 localhost


192.168.11.11 dbserver1

192.168.11.12 dbserver2


192.168.11.21 webserver1

192.168.11.22 webserver2


这些主机名指向IP地址,你可以放置相同的

托管每台服务器上的文件内容。但您也可以使用具有不同IP地址的相同集合

。您暂存和测试服务器

可以指向暂存和测试数据库服务器,并在您的应用程序中设置

设置只需参考您放置的主机名

主机文件。


当您将相同的应用程序移动到生产服务器时,

应用程序将使用相同的名称但连接到备用IP

地址。这是一个很好的方法,因为开发人员没有

来关注服务器上的更改,而只是对常量名称进行代码




或者你可以在部署期间更改

Web.config / App.config的appSettings中的值。如果您正在运行许多

应用程序,这意味着将部署详细信息复制到每个

应用程序并在服务器/网络更改时更新每个应用程序

是制作。


Brennan Stehling
http ://brennan.offwhite.net/blog/


brett写道:
Brett,

Why not use the hosts file? It is located here...

C:\WINDOWS\system32\drivers\etc\hosts

And it would look like this.

127.0.0.1 localhost

192.168.11.11 dbserver1
192.168.11.12 dbserver2

192.168.11.21 webserver1
192.168.11.22 webserver2

These hostnames point to IP addresses and you could place the same
hosts file contents on each server. But you can also use the same set
of names with different IP addresses. You Staging and Testing servers
could point to Staging and Testing database servers and have the
settings in your application simply refer to the hostname you place in
the hosts file.

When you move the identical application to your Production server the
application will use the same names but connect to the alternate IP
addresses. This is a good approach because the developers do not have
to be concerned with changes on the servers and instead just code
against a constant name.

Alternatively you could change the values in the appSettings of your
Web.config/App.config during deployment. If you are running many
applications that means copying the deployment details to each
application and updating each application when a server/network change
is made.

Brennan Stehling
http://brennan.offwhite.net/blog/

brett wrote:

我用两个测试服务器和一个生产。我有一个实用工具类

,其中包含通过该网站使用的许多链接。此类中的一个

变量被分配了域名。我需要

根据我正在使用的服务器自动设置这个值。

域名可以类似于以下任何一个,具体取决于服务器:


- abc.com

- 190.168。 2.100

- 190.168.2.109


最好的方法是什么?


谢谢,

Brett
I use two test servers and one production. I have a Utilities class
that holds many of the links used through the site. One of the
variables in this class is assigned the domain name. I need to
automatically set this value depending on the server I''m on. The
domain can be similar to any of the following depending on the server:

- abc.com
- 190.168.2.100
- 190.168.2.109

What is the best way to do that?

Thanks,
Brett


您真的需要这些链接中的域名吗?如果你使用root relative

链接(即/public/mypage.aspx或〜/ public / mypage.aspx),你可以参考

服务器从哪个页面那个包含此链接服务...


---

Patrice


" brett" < ac ***** @cygen.comaécritdansle message de news:
11 ******** @ n67g2000cwd.googlegroups。 com ...
Do you really need the domain name in those links ? If you use root relative
links (i.e /public/mypage.aspx or ~/public/mypage.aspx), you refer to the
server from which the page that contains this link is served...

---
Patrice

"brett" <ac*****@cygen.coma écrit dans le message de news:
11**********************@n67g2000cwd.googlegroups. com...

>我使用两个测试服务器和一个生产。我有一个实用工具类

,其中包含通过该网站使用的许多链接。此类中的一个

变量被分配了域名。我需要

根据我正在使用的服务器自动设置这个值。

域名可以类似于以下任何一个,具体取决于服务器:


- abc.com

- 190.168。 2.100

- 190.168.2.109


最好的方法是什么?


谢谢,

Brett
>I use two test servers and one production. I have a Utilities class
that holds many of the links used through the site. One of the
variables in this class is assigned the domain name. I need to
automatically set this value depending on the server I''m on. The
domain can be similar to any of the following depending on the server:

- abc.com
- 190.168.2.100
- 190.168.2.109

What is the best way to do that?

Thanks,
Brett





Brennan Stehling写道:

Brennan Stehling wrote:

Brett,


为什么不使用hosts文件?它位于这里...


C:\ WINDOWS \ system32 \ drivers \ etcc \hosts


它看起来像这样。


127.0.0.1 localhost


192.168.11.11 dbserver1

192.168.11.12 dbserver2


192.168.11.21 webserver1

192.168.11.22 webserver2
Brett,

Why not use the hosts file? It is located here...

C:\WINDOWS\system32\drivers\etc\hosts

And it would look like this.

127.0.0.1 localhost

192.168.11.11 dbserver1
192.168.11.12 dbserver2

192.168.11.21 webserver1
192.168.11.22 webserver2



你有各种不同的名字所以我我不确定这有多大帮助。


你的意思是我在每台不同的机器上使用它:


machine1

192.168.11.21 mydomain


machine2

192.168.11.22 mydomain


machine3

192.168.11.23 mydomain


,在代码中只使用mydomain; $而不是localhost或IP?


谢谢,

Brett

You have all different names so I''m not sure how that helps.

Do you mean I get use this on each different machine:

machine1
192.168.11.21 mydomain

machine2
192.168.11.22 mydomain

machine3
192.168.11.23 mydomain

and in the code just use "mydomain" instead of localhost or an IP?

Thanks,
Brett


这篇关于根据服务器切换域名?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆