本文整理汇总了C#中System.Security.Permissions.SecurityPermission类的典型用法代码示例。如果您正苦于以下问题:C# SecurityPermission类的具体用法?C# SecurityPermission怎么用?C# SecurityPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SecurityPermission类属于System.Security.Permissions命名空间,在下文中一共展示了SecurityPermission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Credential
/// <summary>
/// Initializes UnmanagedCodePermission for the <see cref="Credential" /> class.
/// </summary>
static Credential()
{
lock (LockObject)
{
UnmanagedCodePermission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
}
}
示例2: ReflectionFormatterReadSecurityExceptionPropertiesWithoutPermissionTest
public void ReflectionFormatterReadSecurityExceptionPropertiesWithoutPermissionTest()
{
SecurityPermission denyPermission
= new SecurityPermission(SecurityPermissionFlag.ControlPolicy | SecurityPermissionFlag.ControlEvidence);
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(denyPermission);
permissions.Deny();
StringBuilder sb = new StringBuilder();
StringWriter writer = new StringWriter(sb);
SecurityException exception = null;
try
{
DemandException(denyPermission);
}
catch (SecurityException e)
{
exception = e;
}
MockTextExceptionFormatter formatter = new MockTextExceptionFormatter(writer, exception, Guid.Empty);
formatter.Format();
CodeAccessPermission.RevertDeny();
formatter = new MockTextExceptionFormatter(writer, exception, Guid.Empty);
formatter.Format();
Assert.AreEqual(exception.Demanded.ToString(), formatter.properties["Demanded"]);
}
示例3: Correctly_determines_permissions
public void Correctly_determines_permissions()
{
// Execution has to be always granted. Otherwise this code wouldn't run in the first place.
var securityPermission = new SecurityPermission(SecurityPermissionFlag.Execution);
Assert.IsTrue(securityPermission.IsGranted());
}
示例4: Install
public override void Install(IDictionary stateSaver)
{
try
{
SecurityPermission permission =
new SecurityPermission(PermissionState.Unrestricted);
permission.Demand();
}
catch (SecurityException)
{
throw new InstallException(
"You have insufficient privileges to " +
"register a trust relationship. Start Excel " +
"and confirm the trust dialog to run the addin.");
}
Uri deploymentManifestLocation = null;
// NodeXLModification
//
// "deploymentManifestLocation" parameter name changed to
// "deploymentLocation" to make it consistent with
// ClickOnceInstaller.cs.
if (Uri.TryCreate(Context.Parameters["deploymentLocation"],
UriKind.RelativeOrAbsolute, out deploymentManifestLocation) == false)
{
throw new InstallException(
"The location of the deployment manifest is missing or invalid.");
}
AddInSecurityEntry entry = new AddInSecurityEntry(
deploymentManifestLocation, RSA_PublicKey);
UserInclusionList.Add(entry);
stateSaver.Add("entryKey", deploymentManifestLocation);
base.Install(stateSaver);
}
示例5: RunApp
public void RunApp(string FileName, string arg)
{
SecurityPermission SP = new SecurityPermission(SecurityPermissionFlag.AllFlags);
SP.Assert();
//ProcessStartInfo process = new ProcessStartInfo("cmd", "/c " + FileName ));
System.Diagnostics.Process process = new System.Diagnostics.Process();
process.StartInfo.WindowStyle = ProcessWindowStyle.Normal;
//process.StartInfo.UseShellExecute = false;
//process.StartInfo.RedirectStandardOutput = true;
//process.StartInfo.RedirectStandardError = true;
//process.StartInfo.CreateNoWindow = true;
process.StartInfo.FileName = FileName;
process.StartInfo.Arguments = arg;
process.StartInfo.WorkingDirectory = System.IO.Path.GetDirectoryName(FileName);
//Vista or higher check
if (System.Environment.OSVersion.Version.Major >= 6)
process.StartInfo.Verb = "runas";
try
{
process.Start();
process.WaitForExit();
process.Close();
}
catch (InvalidOperationException)
{
//e.ExceptionObject.ToString();
}
}
示例6: CanReflectOnSecurityExceptionWithoutPermission
public void CanReflectOnSecurityExceptionWithoutPermission()
{
SecurityPermission denyPermission
= new SecurityPermission(SecurityPermissionFlag.ControlPolicy | SecurityPermissionFlag.ControlEvidence);
PermissionSet permissions = new PermissionSet(PermissionState.None);
permissions.AddPermission(denyPermission);
permissions.Deny();
SecurityException exception = null;
try
{
DemandException(denyPermission);
}
catch (SecurityException e)
{
exception = e;
}
ExceptionFormatter formatter = new ExceptionFormatter();
String message = formatter.GetMessage(exception);
Match demandedMatch = DemandedEntryRegex.Match(message);
Assert.IsNotNull(demandedMatch);
Assert.AreEqual(Resources.PropertyAccessFailed, demandedMatch.Groups[1].Value);
CodeAccessPermission.RevertDeny();
message = formatter.GetMessage(exception);
demandedMatch = DemandedEntryRegex.Match(message);
Assert.IsNotNull(demandedMatch);
Assert.AreNotEqual(Resources.PropertyAccessFailed, demandedMatch.Groups[1].Value);
}
示例7: BaseCredentialsPrompt
static BaseCredentialsPrompt()
{
lock (_lockObject)
{
_unmanagedCodePermission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
}
}
示例8: Clerk
public Clerk(string compensator, string description, CompensatorOptions flags)
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
permission.Assert();
this.Init(compensator, description, flags);
}
示例9: SetAppDomainData
public static void SetAppDomainData()
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.ControlAppDomain);
sp.Assert();
AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
}
示例10: CodeAccessSecurityEngine
// static default constructor. This will be called before any of the static members are accessed.
static CodeAccessSecurityEngine()
{
#pragma warning disable 618
AssertPermission = new SecurityPermission(SecurityPermissionFlag.Assertion);
#pragma warning restore 618
AssertPermissionToken = PermissionToken.GetToken(AssertPermission);
}
示例11: ClerkMonitor
public ClerkMonitor()
{
SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
permission.Demand();
permission.Assert();
this._monitor = new CrmMonitor();
this._version = 0;
}
示例12: AnimateWindow
internal static void AnimateWindow(Control control, int time, AnimationFlags flags)
{
try
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
AnimateWindow(new HandleRef(control, control.Handle), time, flags);
}
catch (SecurityException) { }
}
示例13: Assert
public void Assert()
{
// We must have the "Assertion" security flag for this to work.
SecurityPermission perm;
perm = new SecurityPermission(SecurityPermissionFlag.Assertion);
perm.Demand();
// Assert this permission.
Assert(2);
}
示例14: _UnsafeGetAssertPermSet
internal static PermissionSet _UnsafeGetAssertPermSet()
{
PermissionSet set = new PermissionSet(PermissionState.None);
RegistryPermission perm = new RegistryPermission(PermissionState.Unrestricted);
set.AddPermission(perm);
EnvironmentPermission permission2 = new EnvironmentPermission(PermissionState.Unrestricted);
set.AddPermission(permission2);
SecurityPermission permission3 = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
set.AddPermission(permission3);
return set;
}
示例15: AnimateWindow
internal static void AnimateWindow(Control control, int time, AnimationFlags flags)
{
Contract.Requires<ArgumentNullException>(control != null);
try
{
SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
sp.Demand();
AnimateWindow(new HandleRef(control, control.Handle), time, flags);
}
catch (SecurityException) { }
}