• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C# Permissions.EnvironmentPermission类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


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


示例17: MainWindow

        public MainWindow()
        {
            this.MoveToOtherContextMenuHeader = "Move to Machine";

            InitializeComponent();

            var permissions = new EnvironmentPermission(EnvironmentPermissionAccess.AllAccess, "PATH");
            permissions.Demand();

            this.DataContext = this;
            uxPaths.ItemsSource = paths;

            this.AddShortcut(new KeyGesture(Key.Z, ModifierKeys.Control), Undo);
            this.AddShortcut(new KeyGesture(Key.Y, ModifierKeys.Control), Redo);
            uxPaths.AddShortcut(new KeyGesture(Key.Up, ModifierKeys.Control), MoveUp);
            uxPaths.AddShortcut(new KeyGesture(Key.Down, ModifierKeys.Control), MoveDown);
            uxPaths.AddShortcut(new KeyGesture(Key.Delete), Delete);

            GongSolutions.Wpf.DragDrop.DragDrop.SetIsDragSource(uxPaths, true);
            GongSolutions.Wpf.DragDrop.DragDrop.SetIsDropTarget(uxPaths, true);
            GongSolutions.Wpf.DragDrop.DragDrop.SetDropHandler(uxPaths, this);
        }
开发者ID:ianobermiller,项目名称:PathSharp,代码行数:22,代码来源:MainWindow.xaml.cs


示例18: TestAssertAndDeny

        public static void TestAssertAndDeny()
        {
            EnvironmentPermission envPermission = new EnvironmentPermission(
               EnvironmentPermissionAccess.Read,
               "COMPUTERNAME;USERNAME;USERDOMAIN");
             envPermission.Assert();
             try
             {
            SomeSecuredMethods.MethodProtectedByDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on Demand " +
               "with the asserted permission.");

            SomeSecuredMethods.MethodProtectedByLinkDemand();
            Console.WriteLine(
               "Caller's Deny has no effect on LinkDemand " +
               "with the asserted permission.");
             }
             catch (SecurityException e)
             {
            Console.WriteLine(
               "Caller's Deny protected the library.{0}", e);
             }
        }
开发者ID:terryjintry,项目名称:OLSource1,代码行数:24,代码来源:ca2107--review-deny-and-permit-only-usage_2.cs


示例19: Intersect

		public override IPermission Intersect (IPermission target)
		{
			EnvironmentPermission ep = Cast (target);
			if (ep == null)
				return null;

			if (IsUnrestricted ())
				return ep.Copy ();
			if (ep.IsUnrestricted ())
				return Copy ();

			int n = 0;
			EnvironmentPermission result = new EnvironmentPermission (PermissionState.None);
			string readTarget = ep.GetPathList (EnvironmentPermissionAccess.Read);
			if (readTarget != null) {
				string[] targets = readTarget.Split (';');
				foreach (string t in targets) {
					if (readList.Contains (t)) {
						result.AddPathList (EnvironmentPermissionAccess.Read, t);
						n++;
					}
				}
			}

			string writeTarget = ep.GetPathList (EnvironmentPermissionAccess.Write);
			if (writeTarget != null) {
				string[] targets = writeTarget.Split (';');
				foreach (string t in targets) {
					if (writeList.Contains (t)) {
						result.AddPathList (EnvironmentPermissionAccess.Write, t);
						n++;
					}
				}
			}
			return ((n > 0) ? result : null);
		}
开发者ID:runefs,项目名称:Marvin,代码行数:36,代码来源:EnvironmentPermission.cs


示例20: Copy

		public override IPermission Copy ()
		{
			EnvironmentPermission ep = new EnvironmentPermission (_state);
			string path = GetPathList (EnvironmentPermissionAccess.Read);
			if (path != null)
				ep.SetPathList (EnvironmentPermissionAccess.Read, path);
			path = GetPathList (EnvironmentPermissionAccess.Write);
			if (path != null)
				ep.SetPathList (EnvironmentPermissionAccess.Write, path);
			return ep;
		}
开发者ID:runefs,项目名称:Marvin,代码行数:11,代码来源:EnvironmentPermission.cs



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C# Permissions.FileIOPermission类代码示例发布时间:2022-05-26
下一篇:
C# Xml.SignedXml类代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap