Reputation: 4807
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
Upvotes: 0
Views: 136
Reputation: 2780
The System.Web.HttpRequest class has an IsLocal property that tells you exactly this. It is a little more robust than using the server variables, as it checks for things like "127.0.0.1".
Upvotes: 1
Reputation: 115488
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.
Upvotes: 1
Reputation: 6838
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
Upvotes: 0