本文整理匯總了C#中System.Security.SecurityException類的典型用法代碼示例。如果您正苦於以下問題:C# SecurityException類的具體用法?C# SecurityException怎麽用?C# SecurityException使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
SecurityException類屬於System.Security命名空間,在下文中一共展示了SecurityException類的1個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。
示例1: Main
//引入命名空間
using Microsoft.Win32;
using System;
using System.Security;
using System.Security.Permissions;
public class Example
{
public static void Main()
{
PermissionSet perms = new PermissionSet(null);
perms.AddPermission(new UIPermission(PermissionState.Unrestricted));
perms.AddPermission(new RegistryPermission(PermissionState.None));
perms.PermitOnly();
try {
RegistryKey key = Registry.CurrentUser.CreateSubKey("MyCompany\\Applications");
Console.WriteLine("Registry key: {0}", key.Name);
}
catch (SecurityException e) {
Console.WriteLine("Security Exception:\n\n{0}", e.Message);
}
}
}
輸出:
Security Exception: Request for the permission of type 'System.Security.Permissions.RegistryPermission, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089' failed.