本文整理汇总了C#中System.Security.PermissionSet.IsSubsetOf方法的典型用法代码示例。如果您正苦于以下问题:C# PermissionSet.IsSubsetOf方法的具体用法?C# PermissionSet.IsSubsetOf怎么用?C# PermissionSet.IsSubsetOf使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Security.PermissionSet
的用法示例。
在下文中一共展示了PermissionSet.IsSubsetOf方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: IsGranted
// Determine if a specific permission has been granted.
public static bool IsGranted(IPermission perm)
{
// Bail out if the requested permission is null.
if(perm == null)
{
return true;
}
// Get the current permission state.
ClrPermissions current = ClrSecurity.GetPermissionsFrom(1);
if(current == null)
{
// Null is equivalent to "unrestricted".
return true;
}
// Build a permission set with just this permission.
PermissionSet set = new PermissionSet(PermissionState.None);
set.AddPermission(perm);
// If "PermitOnly" is set, then only check that set.
if(current.permitOnly != null)
{
return set.IsSubsetOf(current.permitOnly);
}
// The permission must be granted, but not denied.
if(!set.IsSubsetOf(current.granted) ||
set.IsSubsetOf(current.denied))
{
return false;
}
return true;
}
示例2: GetIsRegistryAvailable
/// <summary>
/// Checks to see if Registry access is available to the caller
///
/// </summary>
///
/// <returns/>
public bool GetIsRegistryAvailable()
{
PermissionSet permissionSet = new PermissionSet(PermissionState.None);
RegistryPermission registryPermission = new RegistryPermission(PermissionState.Unrestricted);
permissionSet.AddPermission((IPermission) registryPermission);
return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
}
示例3: CanWriteToFolder
private static bool CanWriteToFolder(string folder)
{
var permission = new FileIOPermission(FileIOPermissionAccess.Write, folder);
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(permission);
return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
}
示例4: GetIsDnsAvailable
/// <summary>
/// Checks to see if DNS information is available to the caller
///
/// </summary>
///
/// <returns/>
public bool GetIsDnsAvailable()
{
PermissionSet permissionSet = new PermissionSet(PermissionState.None);
DnsPermission dnsPermission = new DnsPermission(PermissionState.Unrestricted);
permissionSet.AddPermission((IPermission) dnsPermission);
return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
}
示例5: NeedsAdministratorRights
public static bool NeedsAdministratorRights()
{
var permissionSet = new PermissionSet(PermissionState.None);
var writePermission = new FileIOPermission(FileIOPermissionAccess.Write, HostsFileManager.Filename);
permissionSet.AddPermission(writePermission);
return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
}
示例6: HasSerializationFormatterPermission
private bool HasSerializationFormatterPermission()
{
#if(DOTNET35)
return SecurityManager.IsGranted(new SecurityPermission(SecurityPermissionFlag.SerializationFormatter));
#else
var permission = new PermissionSet(PermissionState.None);
permission.AddPermission(new SecurityPermission(SecurityPermissionFlag.UnmanagedCode));
return permission.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
#endif
}
示例7: CheckAppDomainPermissions
internal static bool CheckAppDomainPermissions(PermissionSet permissions)
{
if (!AppDomain.CurrentDomain.IsHomogenous)
{
return false;
}
else
{
return permissions.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
}
}
示例8: IsGranted
public static bool IsGranted(this IPermission permission)
{
#if DOTNET35 || MONO26
return SecurityManager.IsGranted(permission);
#else
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(permission);
return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
#endif
}
示例9: CheckPermission
private void CheckPermission()
{
var folder = ConfigurationManager.AppSettings["AttachmentsDirectory"];
var permission = new FileIOPermission(FileIOPermissionAccess.Write, Server.MapPath(folder));
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(permission);
if (!permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
WarningLabel.Text = String.Format(CultureInfo.CurrentUICulture, "The directory \"{0}\" is write protected", folder);
//AttachmentPanel.Enabled = false;
}
}
示例10: IsDirectoryWritable
public static bool IsDirectoryWritable(string directory)
{
if (string.IsNullOrWhiteSpace(directory))
{
return false;
}
FileIOPermission permission = new FileIOPermission(FileIOPermissionAccess.Write, HostingEnvironment.MapPath(directory));
PermissionSet permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(permission);
return permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet);
}
示例11: isDirWritable
public static bool isDirWritable(String name,bool isDir=true)
{
try
{
string directoryName = null;
if (isDir)
{
directoryName = name;
}
else
{
directoryName = Path.GetDirectoryName(name);
}
if (!String.IsNullOrEmpty(directoryName))
{
PermissionSet permissionSet = new PermissionSet(PermissionState.None);
FileIOPermission writePermission = new FileIOPermission(FileIOPermissionAccess.Write, directoryName);
permissionSet.AddPermission(writePermission);
if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
return true;
}
else
{
return false;
}
}
}
catch (Exception e)
{
Console.WriteLine(e.Message);
}
return false;
}
示例12: IsSubset_OnePermission
public void IsSubset_OnePermission ()
{
SecurityPermission sp = new SecurityPermission (SecurityPermissionFlag.Assertion);
PermissionSet ps1 = new PermissionSet (PermissionState.None);
ps1.AddPermission (sp);
PermissionSet ps2 = new PermissionSet (PermissionState.None);
Assert.IsTrue (!ps1.IsSubsetOf (null), "PS1.IsSubset(null)");
Assert.IsTrue (!ps1.IsSubsetOf (ps2), "PS1.IsSubset(None)");
Assert.IsTrue (ps2.IsSubsetOf (ps1), "None.IsSubset(PS1)");
PermissionSet ps3 = ps1.Copy ();
Assert.IsTrue (ps1.IsSubsetOf (ps3), "PS1.IsSubset(PS3)");
Assert.IsTrue (ps3.IsSubsetOf (ps1), "PS3.IsSubset(PS1)");
PermissionSet ups1 = new PermissionSet (PermissionState.Unrestricted);
Assert.IsTrue (ps1.IsSubsetOf (ups1), "PS1.IsSubset(Unrestricted)");
Assert.IsTrue (!ups1.IsSubsetOf (ps1), "Unrestricted.IsSubset(PS1)");
}
示例13: IsSubset_Empty
public void IsSubset_Empty ()
{
PermissionSet ps1 = new PermissionSet (PermissionState.None);
PermissionSet ps2 = new PermissionSet (PermissionState.None);
Assert.IsTrue (ps1.IsSubsetOf (null), "None.IsSubsetOf(null)");
Assert.IsTrue (ps1.IsSubsetOf (ps2), "None1.IsSubsetOf(None2)");
Assert.IsTrue (ps2.IsSubsetOf (ps1), "None2.IsSubsetOf(None1)");
PermissionSet ups1 = new PermissionSet (PermissionState.Unrestricted);
Assert.IsTrue (ps1.IsSubsetOf (ups1), "None1.IsSubsetOf(Unrestricted)");
Assert.IsTrue (!ups1.IsSubsetOf (ps1), "Unrestricted.IsSubsetOf(None1)");
Assert.IsTrue (!ups1.IsSubsetOf (null), "Unrestricted.IsSubsetOf(Null)");
PermissionSet ups2 = new PermissionSet (PermissionState.Unrestricted);
Assert.IsTrue (ups1.IsSubsetOf (ups2), "ups1IsSubsetOf(ups2)");
Assert.IsTrue (ups2.IsSubsetOf (ups1), "ups2.IsSubsetOf(ups1)");
}
示例14: Logger
/// <summary>
/// Creates an _instance of logger. If rootDirectory doesn't exist tries to create it.
/// If everything is successfull sets IsInited to true.
/// </summary>
/// <param name="rootDirectory">The directory, where logs should be created.</param>
/// <param name="level">Level of loggin. Pass LogLevel.Off for turning off logging.</param>
/// <exception cref="AtTaskException">
/// Code: FILE_ACCESS_ERROR: when the rootDirectory doesn't exist and couldn't be created or
/// when there is no permosision to write files in that directory
/// </exception>
private Logger(string rootDirectory, LogLevel level)
{
try
{
if (string.IsNullOrEmpty(rootDirectory))
{
rootDirectory = Path.Combine(Directory.GetCurrentDirectory(), "Logs");
//throw new ArgumentException("rootDirectory is null or empty");
return;
}
if (!Directory.Exists(rootDirectory))
{
try
{
Directory.CreateDirectory(rootDirectory);
}
catch (IOException)
{
//throw new AtTaskException(AtTaskExceptionCode.FILE_ACCESS_ERROR, ex);
return;
}
}
FileIOPermission directoryPermission = new FileIOPermission(FileIOPermissionAccess.Append, rootDirectory);
PermissionSet permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(directoryPermission);
if (!permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
//throw new AtTaskException(AtTaskExceptionCode.FILE_ACCESS_ERROR);
return;
}
this.rootDirectory = rootDirectory;
Level = level;
IsInitied = true;
}
catch
{
//DO NOTHING
}
}
示例15: GetContentTypeForExtension
/// <summary>
/// Gets the MIME content type for a given path extension.
/// </summary>
/// <param name="extension">The input path extension.</param>
/// <param name="def">The default content type to return if any error occurs.</param>
/// <returns>The path extension's MIME content type.</returns>
public static string GetContentTypeForExtension(string extension, string def)
{
if (string.IsNullOrEmpty(extension))
{
return def;
}
string contentType = "";
var permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(new RegistryPermission(PermissionState.Unrestricted));
if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
if (MimeTypes.ContainsKey(extension))
contentType = MimeTypes[extension];
else
contentType = def;
}
permissionSet = new PermissionSet(PermissionState.None);
permissionSet.AddPermission(new DnsPermission(PermissionState.Unrestricted));
if (permissionSet.IsSubsetOf(AppDomain.CurrentDomain.PermissionSet))
{
//do something.... not at full trust
try
{
RegistryKey reg = Registry.ClassesRoot;
reg = reg.OpenSubKey(extension, false);
if (reg != null) contentType = (string)reg.GetValue("", def);
}
catch (Exception)
{
contentType = def;
}
}
return contentType;
}