Home > Backend Development > C++ > How to Get the Computer Name and FQDN in .NET?

How to Get the Computer Name and FQDN in .NET?

Susan Sarandon
Release: 2024-12-28 09:19:11
Original
377 people have browsed it

How to Get the Computer Name and FQDN in .NET?

Getting the Computer Name in .NET

Retrieving the computer name is a common task in .NET applications. There are several methods available to accomplish this, depending on the type of application you are developing.

  • Console or WinForms app:

    string computerName = System.Environment.MachineName;
    Copy after login
  • Web app:

    string computerName = HttpContext.Current.Server.MachineName;
    Copy after login
  • Getting the Fully Qualified Domain Name (FQDN):

    string fqdn = System.Net.Dns.GetHostName();
    Copy after login

If System.Net.Dns.GetHostName() does not provide the FQDN and you require it, refer to this resource: [How to find FQDN of local machine in C#/.NET?](https://stackoverflow.com/questions/854213/how-to-find-fqdn-of-local-machine-in-c-net)

For additional insights, review this article: [Difference between SystemInformation.ComputerName, Environment.MachineName, and Net.Dns.GetHostName](https://codereview.stackexchange.com/questions/37366/difference-between-systeminformation-computername-environment-machinenam).

The above is the detailed content of How to Get the Computer Name and FQDN in .NET?. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Latest Articles by Author
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template