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


C# Permissions.EnvironmentPermission类代码示例

本文整理汇总了C#中System.Security.Permissions.EnvironmentPermission的典型用法代码示例。如果您正苦于以下问题:C# EnvironmentPermission类的具体用法?C# EnvironmentPermission怎么用?C# EnvironmentPermission使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


EnvironmentPermission类属于System.Security.Permissions命名空间,在下文中一共展示了EnvironmentPermission类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: EnvironmentSetting

        public static string EnvironmentSetting(string environmentVariable)
        {
            EnvironmentPermission envPermission = new EnvironmentPermission( EnvironmentPermissionAccess.Read,environmentVariable);
             envPermission.Assert();

             return Environment.GetEnvironmentVariable(environmentVariable);
        }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:7,代码来源:ca2122--do-not-indirectly-expose-methods-with-link-demands_1.cs

示例2: Main

        public static void Main()
        {
            TestMethodLevelSecurity me = new TestMethodLevelSecurity();

             me.dataHolder = new MyClassWithTypeSecurity(1964,06,16);

             // Local computer zone starts with all environment permissions.
             me.RetrievePersonalInformation("[All permissions]");

             // Deny the write permission required by the type.
             EnvironmentPermission epw = new EnvironmentPermission(
            EnvironmentPermissionAccess.Write,"PersonalInfo");
             epw.Deny();

             // Even though the type requires write permission,
             // and you do not have it; you can get the data.
             me.RetrievePersonalInformation(
            "[No write permission (demanded by type)]");

             // Reset the permissions and try to get
             // data without read permission.
             CodeAccessPermission.RevertAll();

             // Deny the read permission required by the method.
             EnvironmentPermission epr = new EnvironmentPermission(
            EnvironmentPermissionAccess.Read,"PersonalInfo");
             epr.Deny();

             // The method requires read permission, and you
             // do not have it; you cannot get the data.
             me.RetrievePersonalInformation(
            "[No read permission (demanded by method)]");
        }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:33,代码来源:ca2114--method-security-should-be-a-superset-of-type_2.cs

示例3: Main

        public static void Main()
        {
            EnvironmentPermission envPermission = new EnvironmentPermission(
            EnvironmentPermissionAccess.Read,
            "COMPUTERNAME;USERNAME;USERDOMAIN");
             envPermission.Deny();

             //Test Deny and Assert interaction for LinkDemands and Demands.
             TestAssertAndDeny();

             //Test Deny's effects on code in different stack frame.
             TestDenyAndLinkDemand();

             //Test Deny's effect on code in same frame as deny.
             try
             {
            SomeSecuredMethods.MethodProtectedByLinkDemand();
            Console.WriteLine(
               "This Deny has no effect with LinkDemand-protected code.");
             }
             catch (SecurityException e)
             {
            Console.WriteLine("This Deny protected the library.{0}",e);
             }
        }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:25,代码来源:ca2107--review-deny-and-permit-only-usage_2.cs

示例4: PermissionStateUnrestricted

		public void PermissionStateUnrestricted () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted);
			Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.Unrestricted)");
			Assert.IsTrue (ep.IsUnrestricted (), "IsUnrestricted");
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = ep.ToXml ();
			Assert.AreEqual ("true", (se.Attributes ["Unrestricted"] as string), "ToXml-Unrestricted");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:10,代码来源:EnvironmentPermissionTest.cs

示例5: InitializePart1

 void InitializePart1() {
     if (m_environmentUserNamePermission == null) {
         lock(lockingObject) {
             if (m_environmentUserNamePermission == null) {
                 m_environmentDomainNamePermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERDOMAIN");
                 m_environmentUserNamePermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, "USERNAME");
             }
         }
     }
 }
开发者ID:gbarnett,项目名称:shared-source-cli-2.0,代码行数:10,代码来源:networkcredential.cs

示例6: PermissionStateUnrestricted

		public void PermissionStateUnrestricted () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.Unrestricted);
			AssertNotNull ("EnvironmentPermission(PermissionState.Unrestricted)", ep);
			Assert ("IsUnrestricted", ep.IsUnrestricted ());
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = ep.ToXml ();
			AssertEquals ("ToXml-Unrestricted", "true", (se.Attributes ["Unrestricted"] as string));
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:10,代码来源:EnvironmentPermissionTest.cs

示例7: _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

示例8: PermissionStateNone

		public void PermissionStateNone () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			Assert.IsNotNull (ep, "EnvironmentPermission(PermissionState.None)");
			Assert.IsTrue (!ep.IsUnrestricted (), "IsUnrestricted");
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			Assert.AreEqual (ep.IsUnrestricted (), copy.IsUnrestricted (), "Copy.IsUnrestricted");
			SecurityElement se = ep.ToXml ();
			Assert.IsTrue ((se.Attributes ["class"] as string).StartsWith (className), "ToXml-class");
			Assert.AreEqual ("1", (se.Attributes ["version"] as string), "ToXml-version");
		}
开发者ID:nlhepler,项目名称:mono,代码行数:11,代码来源:EnvironmentPermissionTest.cs

示例9: PermissionStateNone

		public void PermissionStateNone () 
		{
			EnvironmentPermission ep = new EnvironmentPermission (PermissionState.None);
			AssertNotNull ("EnvironmentPermission(PermissionState.None)", ep);
			Assert ("IsUnrestricted", !ep.IsUnrestricted ());
			EnvironmentPermission copy = (EnvironmentPermission) ep.Copy ();
			AssertEquals ("Copy.IsUnrestricted", ep.IsUnrestricted (), copy.IsUnrestricted ());
			SecurityElement se = ep.ToXml ();
			Assert ("ToXml-class", (se.Attributes ["class"] as string).StartsWith (className));
			AssertEquals ("ToXml-version", "1", (se.Attributes ["version"] as string));
		}
开发者ID:jjenki11,项目名称:blaze-chem-rendering,代码行数:11,代码来源:EnvironmentPermissionTest.cs

示例10: XamlSourceInfoHelper

 static XamlSourceInfoHelper()
 {
     // Check environment variable
     const string environmentVariable = "ENABLE_XAML_DIAGNOSTICS_SOURCE_INFO";
     EnvironmentPermission environmentPermission = new EnvironmentPermission(EnvironmentPermissionAccess.Read, environmentVariable);
     environmentPermission.Assert();
     try
     {
         InitializeEnableXamlSourceInfo(Environment.GetEnvironmentVariable(environmentVariable));
     }
     finally
     {
         EnvironmentPermission.RevertAssert();
     }
 }
开发者ID:mind0n,项目名称:hive,代码行数:15,代码来源:XamlSourceInfoHelper.cs

示例11: CreatePermission

 public override IPermission CreatePermission()
 {
     if (base.m_unrestricted)
     {
         return new EnvironmentPermission(PermissionState.Unrestricted);
     }
     EnvironmentPermission permission = new EnvironmentPermission(PermissionState.None);
     if (this.m_read != null)
     {
         permission.SetPathList(EnvironmentPermissionAccess.Read, this.m_read);
     }
     if (this.m_write != null)
     {
         permission.SetPathList(EnvironmentPermissionAccess.Write, this.m_write);
     }
     return permission;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:17,代码来源:EnvironmentPermissionAttribute.cs

示例12: GetMachineNameWithoutPermissions

        /// <summary>
        /// Try/finally is completely unnecessary. Permissions are associated with stack frames
        /// and go out of scope once stack frame returns.
        /// </summary>
        private string GetMachineNameWithoutPermissions()
        {
            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.None);

            PermissionSet permissions = new PermissionSet(PermissionState.None);
            permissions.AddPermission(denyPermission);
            permissions.Deny();

            try
            {
                return Environment.MachineName;
            }
            finally
            {
                CodeAccessPermission.RevertDeny();
            }
        }
开发者ID:bnantz,项目名称:NCS-V1-1,代码行数:21,代码来源:CasFixture.cs

示例13: CreatePermission

		// Methods
		public override IPermission CreatePermission ()
		{
#if NET_2_1
			return null;
#else
			EnvironmentPermission perm = null;
			if (this.Unrestricted)
				perm = new EnvironmentPermission (PermissionState.Unrestricted);
			else {
				perm = new EnvironmentPermission (PermissionState.None);
				if (read != null)
					perm.AddPathList (EnvironmentPermissionAccess.Read, read);
				if (write != null)
					perm.AddPathList (EnvironmentPermissionAccess.Write, write);
			}
			return perm;
#endif
		}
开发者ID:runefs,项目名称:Marvin,代码行数:19,代码来源:EnvironmentPermissionAttribute.cs

示例14: _UnsafeGetAssertPermSet

        internal static PermissionSet _UnsafeGetAssertPermSet() {
            // SEC_NOTE: All callers should already be guarded by EventLogPermission demand.
            PermissionSet permissionSet = new PermissionSet(PermissionState.None);

            // We need RegistryPermission 
            RegistryPermission registryPermission = new RegistryPermission(PermissionState.Unrestricted);
            permissionSet.AddPermission(registryPermission);

            // It is not enough to just assert RegistryPermission, for some regkeys
            // we need to assert EnvironmentPermission too
            EnvironmentPermission environmentPermission = new EnvironmentPermission(PermissionState.Unrestricted);
            permissionSet.AddPermission(environmentPermission);

            // For remote machine registry access UnmanagdCodePermission is required.
            SecurityPermission securityPermission = new SecurityPermission(SecurityPermissionFlag.UnmanagedCode);
            permissionSet.AddPermission(securityPermission);

            return permissionSet;
        }
开发者ID:iskiselev,项目名称:JSIL.NetFramework,代码行数:19,代码来源:EventLog.cs

示例15: Copy

 public override IPermission Copy()
 {
     EnvironmentPermission permission = new EnvironmentPermission(PermissionState.None);
     if (this.m_unrestricted)
     {
         permission.m_unrestricted = true;
         return permission;
     }
     permission.m_unrestricted = false;
     if (this.m_read != null)
     {
         permission.m_read = this.m_read.Copy();
     }
     if (this.m_write != null)
     {
         permission.m_write = this.m_write.Copy();
     }
     return permission;
 }
开发者ID:pritesh-mandowara-sp,项目名称:DecompliedDotNetLibraries,代码行数:19,代码来源:EnvironmentPermission.cs


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