Detecting Asp.net is Running Under Linux


As of now asp.net can run on Linux mono, we need to detect underplaying OS. To detecting this we can use Environment class Platform property which return value of under laying OS PlatformID.

public enum PlatformID
    {
        //
        // Summary:
        //     The operating system is Win32s. Win32s is a layer that runs on 16-bit versions
        //     of Windows to provide access to 32-bit applications.
        Win32S = 0,
        //
        // Summary:
        //     The operating system is Windows 95 or Windows 98.
        Win32Windows = 1,
        //
        // Summary:
        //     The operating system is Windows NT or later.
        Win32NT = 2,
        //
        // Summary:
        //     The operating system is Windows CE.
        WinCE = 3,
        //
        // Summary:
        //     The operating system is Unix.
        Unix = 4,
        //
        // Summary:
        //     The development platform is Xbox 360.
        Xbox = 5,
        //
        // Summary:
        //     The operating system is Macintosh.
        MacOSX = 6
    }

Example to detect that OS is Linux

public static bool IsLinux
{
    get
    {
        var p = (int)Environment.OSVersion.Platform;
        return (p == 4) || (p == 128);
    }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.