当前位置: 首页>>代码示例>>C#>>正文


C# Permissions.SecurityPermission类代码示例

本文整理汇总了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);
     }
 }
开发者ID:zidad,项目名称:Simple.CredentialsManager,代码行数:10,代码来源:Credential.cs

示例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"]);
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:30,代码来源:ExceptionFormatterFixture.2008.cs

示例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());
		}
开发者ID:jeremymeng,项目名称:Core,代码行数:7,代码来源:PermissionUtilTestCase.cs

示例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);
        }
开发者ID:haisreekanth,项目名称:NetMap,代码行数:35,代码来源:TrustInstaller.cs

示例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();
            }
        }
开发者ID:swmicro,项目名称:CHMedit,代码行数:31,代码来源:Form1.cs

示例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);
		}
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:32,代码来源:ExceptionFormatterFixture.cs

示例7: BaseCredentialsPrompt

 static BaseCredentialsPrompt()
 {
     lock (_lockObject)
     {
         _unmanagedCodePermission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
     }
 }
开发者ID:CuneytKukrer,项目名称:TestProject,代码行数:7,代码来源:BaseCredentialsPrompt.cs

示例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);
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:7,代码来源:Clerk.cs

示例9: SetAppDomainData

        public static void SetAppDomainData()
        {
            SecurityPermission sp = new SecurityPermission(SecurityPermissionFlag.ControlAppDomain);
            sp.Assert();

            AppDomain.CurrentDomain.SetData("SQLServerCompactEditionUnderWebHosting", true);
        }
开发者ID:mclricardo,项目名称:DotNetMagazineChat,代码行数:7,代码来源:Global.asax.cs

示例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);
        }
开发者ID:kouvel,项目名称:coreclr,代码行数:8,代码来源:CodeAccessSecurityEngine.cs

示例11: ClerkMonitor

 public ClerkMonitor()
 {
     SecurityPermission permission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
     permission.Demand();
     permission.Assert();
     this._monitor = new CrmMonitor();
     this._version = 0;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:8,代码来源:ClerkMonitor.cs

示例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) { }
 }
开发者ID:devfinity-fx,项目名称:cpms_z,代码行数:10,代码来源:NativeMethods.cs

示例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);
			}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:10,代码来源:CodeAccessPermission.cs

示例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;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:11,代码来源:EventLog.cs

示例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) { }
        }
开发者ID:xieguigang,项目名称:Reference_SharedLib,代码行数:12,代码来源:NativeMethods.cs


注:本文中的System.Security.Permissions.SecurityPermission类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。