473,473 Members | 1,482 Online
Bytes | Software Development & Data Engineering Community
Create Post

Home Posts Topics Members FAQ

Switching Domain name depending on server?

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

Nov 30 '06 #1
11 2230
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:
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
Nov 30 '06 #2
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...
>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

Nov 30 '06 #3

Brennan Stehling wrote:
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
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

Nov 30 '06 #4

Patrice wrote:
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...
Using your suggestion, say I create a static variable:

public static LinkOne = "test/testone.aspx";

The above page is actually in root/test/testone.aspx

I have these two pages:

root/mydir/somepage.aspx
root/somedir/subdir/anotherpage.aspx

If I stick the LinkOne variable into any of the above pages, it won't
work. Both pages will look for test/testone.aspx in their respective
directories. But testone.aspx is in the root. That's the problem,
when pages are located in varied directory structures, how do you use a
relative path in a variable?

Brett

Nov 30 '06 #5
I thought the question was about connecting with database and web
services on other hosts. If a relative path to pages within the same
site is all you need, you can use the utility methods I use.

http://svn.offwhite.net/svn/SmallSha...ode/Utility.cs

I discovered these methods in the Commerce Starter Kit originally and
have adjusted them to suite my needs. You just provide a path like
this...

~/someDirectory/page.aspx

It will change the tilde (~) to the root of the current website.

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

brett wrote:
Patrice wrote:
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...

Using your suggestion, say I create a static variable:

public static LinkOne = "test/testone.aspx";

The above page is actually in root/test/testone.aspx

I have these two pages:

root/mydir/somepage.aspx
root/somedir/subdir/anotherpage.aspx

If I stick the LinkOne variable into any of the above pages, it won't
work. Both pages will look for test/testone.aspx in their respective
directories. But testone.aspx is in the root. That's the problem,
when pages are located in varied directory structures, how do you use a
relative path in a variable?

Brett
Nov 30 '06 #6
This link is relative to the current location. Instead use public static
LinkOne = "/root/test/testone.aspx"; or public static LinkOne =
"~/root/test/testone.aspx"; (note the leading / or ~/) that is a location
that is relative to the web site root or to the web application root (note
that ~ is processed server side i.e. it will work if processed by an ASP.NET
control or explicitely resolved).

--
Patrice

"brett" <ac*****@cygen.coma écrit dans le message de news:
11**********************@j44g2000cwa.googlegroups. com...
>
Patrice wrote:
>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...

Using your suggestion, say I create a static variable:

public static LinkOne = "test/testone.aspx";

The above page is actually in root/test/testone.aspx

I have these two pages:

root/mydir/somepage.aspx
root/somedir/subdir/anotherpage.aspx

If I stick the LinkOne variable into any of the above pages, it won't
work. Both pages will look for test/testone.aspx in their respective
directories. But testone.aspx is in the root. That's the problem,
when pages are located in varied directory structures, how do you use a
relative path in a variable?

Brett

Nov 30 '06 #7

Patrice wrote:
This link is relative to the current location. Instead use public static
LinkOne = "/root/test/testone.aspx"; or public static LinkOne =
"~/root/test/testone.aspx"; (note the leading / or ~/) that is a location
that is relative to the web site root or to the web application root (note
that ~ is processed server side i.e. it will work if processed by an ASP.NET
control or explicitely resolved).
That doesn't work. If I use backslashes, it starts from c:\. If I use
the a forward slashes, it starts in Windows\System32. ~ doesn't make
any difference.

Dec 1 '06 #8
This is what I want:

Path.Combine(AppDomain.CurrentDomain.BaseDirectory , myRelativePath);

Dec 1 '06 #9
humm...Not sure I understood the initial question.

To me a "link" is an hyperlink. It looked like to me you were trying to
build (hyper)links in a web page referring to the server you are running on.

Now It looks like to me you want to find the physical location in the file
system that match a particular url location. Also I don't see how it has
something to do with the domain name...

Usually this is done with Server.MapPath that will take also in to account
virtual directories. For example if you create a virtual directory that maps
to a network share (or redirect to some local location), using
Server.MapPath will return the appropriate location (while the Path.Combine
method will return an improper location as it always assume that it is under
the web site root)

For example :
- create a site in c:\inetpub\wwwroot
- create an image directory below
- create a shared virtual dir "test" that maps to c:\tmp

Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "\images"); and
Server.MapPath("/images") will return "c:\inetpub\wwwroot\images")
Path.Combine(AppDomain.CurrentDomain.BaseDirectory , "\test"); will return
"c:\inetpub\wwwroot\test" while Server.MapPath("/test") will return
"c:\temp")

Server.MapPath("~/test") will return the same path.

Now if you move this site in a "subweb" directory Server.MapPath("/images")
will still return "c:\inetpub\wwwroot\images" as this is related to the web
site root while server.MapPath("~/images") will return
"c:\inetpub\wwwroot\subweb\images" as this is related to the web application
root.

--
Patrice

"brett" <ac*****@cygen.coma écrit dans le message de news:
11**********************@j44g2000cwa.googlegroups. com...
This is what I want:

Path.Combine(AppDomain.CurrentDomain.BaseDirectory , myRelativePath);

Dec 1 '06 #10

Patrice wrote:
humm...Not sure I understood the initial question.

To me a "link" is an hyperlink. It looked like to me you were trying to
build (hyper)links in a web page referring to the server you are running on.

Now It looks like to me you want to find the physical location in the file
system that match a particular url location. Also I don't see how it has
something to do with the domain name...
Sorry. I wasn't so clear on it. It is a physical file I'm accessing
and displaying the contents of in a webform. The website folder
structure is always the same but its location changes depending on the
server. Do you forsee any issues with how I'm using it now? It seems
to work fine.

Thanks,
Brett

Dec 1 '06 #11

Hi, Brett

Use
System.DiagnoticService.ActiveDirectory.Domain.Get CurrentDomain().GetDomainEnry().path
this is a static calss get the current system domain path, So this will
be give a flexeble if the file path has the same in both servers.

all the best .
On Nov 30, 8:21 pm, "brett" <acco...@cygen.comwrote:
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
Dec 2 '06 #12

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
by: Captain Ranger McCoy | last post by:
Hello! Suppose I have ten servers at ten ips: x.x.x.1 x.x.x.2 x.x.x.3 x.x.x.4 and so on Each server hosts 100+ photo galleries, all under a single domain name,
4
by: sashan | last post by:
Hi Is there a way to enable Emacs/Vim style buffer switching in the VC++ editor? For those that don't know this is where you hit a shortcut key in Emacs/Vim and then type the partial name of the...
3
by: Wysiwyg | last post by:
After a server created cookie is processed on the client I want it removed, cleared, or expired in the javascript block but have been unable to do this. If I set a cookie value in the server code...
5
by: Dany C. | last post by:
We have install a valid SSL certificate issued to www.mycompany.com on our web server running IIS 6.0 / win2003 SP1. Then we have created a sub domain pointing to the same server for our web...
10
by: Sridhar | last post by:
HI, I am having problems setting up a website so that it will be available only inside the domain. We have three servers. One is iis server and second one is internal server and the third one is...
2
by: llevity | last post by:
I have a project in progress, and for various reasons, need to switch it from using the integrated ASP.NET development server to IIS. The problem is, I cannot figure out how. After many...
7
by: Danny | last post by:
Hello: I would like to develop a browser extension, or whatever such a thing is classified as, that would allow a user of IE6, and possibly IE7, to switch between a live and development page. ...
6
by: Bart Van der Donck | last post by:
Hello, I'm presenting my new library 'AJAX Cross Domain' - a javascript extension that allows to perform cross-domain AJAX requests. http://www.ajax-cross-domain.com/ Any comments or...
0
by: Uli Netzer | last post by:
Hi all, I'm trying to add a user from another domain (domain trust and rights are there) to a group in our domain. It's a domain local security group. I get the following errors: The server...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
1
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
muto222
php
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.