You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I am trying to check if .NetCore code is running as sudo/admin on Linux. It works on Windows but throws exception on Linux.
How do I check if app is run by admin/sudo on Ubuntu Linux by using .NET Core2.0 build-in class?
Here is the code I have tried (however i thought that it will not manage admin rights on Linux):
using System;
using System.Security.Principal;
namespace smallTestsCore
{
class Program
{
static void Main(string[] args)
{
Console.WriteLine(Program.IsAdministrator);
Console.ReadLine();
}
public static bool IsAdministrator =>
new WindowsPrincipal(WindowsIdentity.GetCurrent())
.IsInRole(WindowsBuiltInRole.Administrator);
}
}
The code works on Windows, but does not work on Linux:
Exception has occurred: CLR/System.PlatformNotSupportedException
An unhandled exception of type 'System.PlatformNotSupportedException' occurred in
System.Security.Principal.Windows.dll: 'Windows Principal functionality is not supported on this platform.'
at System.Security.Principal.WindowsIdentity.GetCurrent()
at adminTst.Program.get_IsAdministrator() in /home/user/adminTst/Program.cs:line 15
at adminTst.Program.Main(String[] args) in /home/user/adminTst/Program.cs:line 11
The text was updated successfully, but these errors were encountered:
I am trying to check if .NetCore code is running as sudo/admin on Linux. It works on Windows but throws exception on Linux.
How do I check if app is run by admin/sudo on Ubuntu Linux by using .NET Core2.0 build-in class?
Here is the code I have tried (however i thought that it will not manage admin rights on Linux):
The code works on Windows, but does not work on Linux:
The text was updated successfully, but these errors were encountered: