views:

33

answers:

2

I have a web app that is using the 3.5 framework. I wanted to know how can I detect what webhost is rendering the page.

If the server is localhost, then send email notification to [email protected] If the server is QA, then send email to [email protected]

Thanks

+1  A: 

The closest your probably going to get with what you want is the machine name:

System.Environment.MachineName

localhost is an address, and every machine can access itself through it (assuming someone didn't monkey with the hosts file).

You could get the URL accessing the page: Request.Url.AbsoluteUri. This will tell you most likely what environment they are trying to hit (except if they use local host to access the site).

If the server is localhost, then send email notification to [email protected] If the server is QA, then send email to [email protected]

If you have access to the machine config, an easier way might be to place the email address in the appsettings you want to send emails to there. That way you can vary it by environment and not worry about what machine/url they are trying to hit.

Kevin
where in machine.config would I add the email addr?
user279521
you can place it in the appsettings portion and access the key by name.
Kevin
A: 

Assuming you mean to do this detection server-side, then how about the old-fashioned ServerVariables ?

string serverName = Request.ServerVariables["SERVER_NAME"];
string httpHost = Request.ServerVariables["HTTP_HOST"];

A full list of server variables is here: http://www.aspcode.net/List-of-RequestServerVariables.aspx

Neil Moss