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


C# EnvironmentPermission.Deny方法代码示例

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


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

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

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

示例3: RollingFlatFileTraceListenerReplacedEnviromentVariablesWillFallBackIfNotPrivilegesToRead

        public void RollingFlatFileTraceListenerReplacedEnviromentVariablesWillFallBackIfNotPrivilegesToRead()
        {
            string environmentVariable = "%USERPROFILE%";
            string fileName = Path.Combine(environmentVariable, "foo.log");

            EnvironmentPermission denyPermission = new EnvironmentPermission(PermissionState.Unrestricted);
            denyPermission.Deny();

            try
            {
                RollingFlatFileTraceListener listener = new RollingFlatFileTraceListener(fileName, "header", "footer", null, 1, "", RollFileExistsBehavior.Increment, RollInterval.Day);
                listener.TraceData(new TraceEventCache(), "source", TraceEventType.Error, 1, "This is a test");
                listener.Dispose();
            }
            finally
            {
                EnvironmentPermission.RevertAll();
            }

            Assert.Fail("Permission was not denied.");
        }
开发者ID:jmeckley,项目名称:Enterprise-Library-5.0,代码行数:21,代码来源:RollingFlatFileTraceListenerFixture.2008.cs


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