本文整理汇总了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;
}