本文整理匯總了C#中System.Security.AccessControl.FileSecurity.GetOwner方法的典型用法代碼示例。如果您正苦於以下問題:C# FileSecurity.GetOwner方法的具體用法?C# FileSecurity.GetOwner怎麽用?C# FileSecurity.GetOwner使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類System.Security.AccessControl.FileSecurity
的用法示例。
在下文中一共展示了FileSecurity.GetOwner方法的2個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: GetOwnershipTest2
public void GetOwnershipTest2()
{
// Arrange
var tmpDir = Path.Combine(Path.GetTempPath(), "dirtools-test-" + Guid.NewGuid().ToString());
Directory.CreateDirectory(tmpDir);
var tmpFile = Path.Combine(tmpDir, "asdf");
var localSystem = new SecurityIdentifier(WellKnownSidType.BuiltinAdministratorsSid, null);
var fileSec = new FileSecurity();
fileSec.SetOwner(localSystem);
File.Create(tmpFile, 1, FileOptions.None, fileSec).Dispose();
// Act
var curIdentity = new NTAccount(Environment.UserDomainName, Environment.UserName);
DirectoryTools.GetOwnershipForDirectory(tmpFile, curIdentity);
// Assert
var curFilesec = new FileSecurity(tmpFile, AccessControlSections.Owner);
IdentityReference owner = curFilesec.GetOwner(typeof(NTAccount));
Assert.IsTrue(curIdentity == owner);
}
示例2: getFileOwner
private string getFileOwner(string filename)
{
FileSecurity tmp = new FileSecurity(filename, AccessControlSections.Owner);
string owner = "<unknown>";
try
{
owner = tmp.GetOwner(System.Type.GetType("System.Security.Principal.SecurityIdentifier")).Value;
}
catch { }
return owner;
}