Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how find identity of server

Status
Not open for further replies.

oakgrove

Programmer
Sep 22, 2002
51
US
Hi all,
Is there a way (in the code) to find out the identity of the server that is running an aspx page? I need to have different connection strings for my development and my deployed machine. My idea is to have both strings in the code and specify the correct one at run time by reading the identity of the server. Does this sound like a workable idea?


 
Hi Oakgrove

You can get the machine name from the server variables collection like this.
Code:
Request.ServerVariables["HTTP_HOST"]
However i would NOT recommend this approach for solvign your problem. In asp.net we can use the web.config file to stor configuration settings and then access them from the code. The config fiel is server specific and is not designed to be uploaded with every version of your application. An example web.config below with an appSetting containing a dummy dsn string...
Code:
<configuration>
	<appSettings>
	       <add key=&quot;DSN&quot; value=&quot;server=server;data source=database;user id=username;password=password&quot; />
	</appSettings>
	<system.web>
	</system.web>
</configuration>
You can access this from your code behind using...
Code:
System.Configuration.ConfigurationSettings.AppSettings[&quot;DSN&quot;]

Hope this helps

Rob

Go placidly amidst the noise and haste, and remember what peace there may be in silence - Erhmann 1927
 
<add key=&quot;ConnectionString&quot; value=&quot;data source=(local);initial catalog=DatabaseName;user id=xxxxxx;password=yyyyyyy&quot; />

This is also a valid connection string. If you have the application and SQL Server on the same machine this will work.
 
Thanks for your help I will go with the config idea. Should have thought of that first.
Thanks again



 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top