473,811 Members | 3,298 Online
Bytes | Software Development & Data Engineering Community
+ 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 2262
Brett,

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

C:\WINDOWS\syst em32\drivers\et c\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************* *********@n67g2 00...legr oups.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\syst em32\drivers\et c\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.asp x

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.asp x

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************* *********@j44g2 00...legr oups.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.asp x

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\System3 2. ~ doesn't make
any difference.

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

Path.Combine(Ap pDomain.Current Domain.BaseDire ctory, 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\wwwr oot
- create an image directory below
- create a shared virtual dir "test" that maps to c:\tmp

Path.Combine(Ap pDomain.Current Domain.BaseDire ctory, "\images"); and
Server.MapPath( "/images") will return "c:\inetpub\www root\images")
Path.Combine(Ap pDomain.Current Domain.BaseDire ctory, "\test"); will return
"c:\inetpub\www root\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\www root\images" as this is related to the web
site root while server.MapPath( "~/images") will return
"c:\inetpub\www root\subweb\ima ges" as this is related to the web application
root.

--
Patrice

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

Path.Combine(Ap pDomain.Current Domain.BaseDire ctory, myRelativePath) ;

Dec 1 '06 #10

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

Similar topics

10
2284
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
2036
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 file/buffer/window and it provides a list of matches to the partial name. It's kinda like hitting Ctrl+i and doing an incremental search except it matches file names instead of text. Any alternative suggestions for quickly moving between files...
3
11130
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 behind and don't use a domain then I can not change or remove that cookie's value on the client. If I subsequently create the cookie again in the codebehind then I actually end up with TWO cookies with the same name in the response. The cookie...
5
2711
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 services at ws.mycompany.com. We have properly installed the server certificate on the client machine. When the client try to connect to our secure webservice at https:\\ws.mycompany.com we have the foolwing error: System.Net.WebException: The...
10
2204
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 sql server. I have deployed the web application in the internal server. It is not able to access the sql server that is on another server. If I deploy the same application on IIS, it is working fine. How should I set up the web application in the...
2
1300
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 searches, I've come across a couple of examples that show how to change it through the project properties. The problem is my project properties do not have a "Web" option, and my dialog box looks different. The examples I've seen have the side options...
7
2733
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. I'm sure the individuals reading this are familiar with what I'm referring to; however, I'll provide an example.
6
5485
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 suggestions are welcome. --
0
1638
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 is can't process the request. HRESULT: 0x80072035 or The object cannot be found on the server HRESULT: 0x80072030 depending on what code I use. I've read that the 8007 error code says it's a AD problem. That doesn't help
0
9727
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
10647
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, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10386
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
10398
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9204
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, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6889
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 then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5692
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
2
3865
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3017
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.