leora
leora

Reputation: 196781

Get the server machine name in ASP.NET MVC?

I have some code that generates an email and I want to include the actual server machine name that is running in the body of the email. (It's a clustered web environment, so I want to find out what actual machine is sending the email.)

I know I can use Request.Url.AbsoluteUri, but that gives me the URL (like www.mysite.com/MyController/Action) instead of the raw actual machine name - which might be MACH3234k323).

Is there a way that I can get the actual server machine's name?

Upvotes: 45

Views: 35391

Answers (3)

kravits88
kravits88

Reputation: 13049

Request.ServerVariables["SERVER_NAME"]

Upvotes: 2

Chris Adams
Chris Adams

Reputation: 1018

The name of the machine will be here:

System.Environment.MachineName

Upvotes: 23

Tomislav Markovski
Tomislav Markovski

Reputation: 12366

Use System.Environment.MachineName

Upvotes: 104

Related Questions