ASP.NET c#: different web.config for different domains

Hi all

I have a website which communicates with an SQL database. In the websites web.config file, I create a "ConnectionString" to tell the program where the database is located. The website is made in Visual Studio 2010 and it is running Framework 4.

At the moment I run the website and database on a test server from a test domain. I have now moved the website to another server and database, and run the website from another domain.

Is it possible to create two web.config files, so that when I open the website on my test domain, it will connect to the database on the test server, and when I connect to the website on the "active" domain, it will connect to the database on the "active" server?

Both servers and domains are up and running, all I need is a way to connect to the right database depending on which domain I open the site from.

If any more information is needed, don't hesitate to ask.

Regards
Søren Augustesen
LVL 1
poultarpAsked:
Who is Participating?
 
Amgad_Consulting_CoConnect With a Mentor Commented:
Hi,

you can make the connection string in an external file, so whenever you update the web.config file, you will not have to fix the connection string

example:

create file "Connection.config"

<?xml version="1.0"?>
  <connectionStrings>
    <add name="ConnectionString" connectionString="Data Source=198.162.1.1;Initial Catalog=datatbase;User ID=username; Password=password;Connect Timeout=0" providerName="System.Data.SqlClient"/>
  </connectionStrings>


in web.config change connection string tag to this

 <connectionStrings configSource="Connection.config"/>


This should fix your problem
0
 
Manoj PatilConnect With a Mentor Sr. Software EngineerCommented:
Hi,
If you are the administrator of the website then you can create a sub-domain in your Domain.
If you create a sub-domain then you can execute your both sites with different Web.config

When you create sub-domain then it will create a folder of the sub-domain name in root folder.

you can upload complete website with web.config in that folder

the browser path will be like :

http://subDomain.MainDomain.com/Default.aspx
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.