StorePermissionAttribute コンストラクタ
アセンブリ: System (system.dll 内)


StorePermissionAttribute を使用して、ストアに追加するためのアクセス許可を拒否するコード例を次に示します。このコード例は、StorePermission クラスのトピックで取り上げているコード例の一部分です。
'Deny the permission the ability to add to a store. <StorePermission(SecurityAction.Deny, Flags:=StorePermissionFlags.AddToStore)> _ Private Shared Sub AddToStore(ByVal cert As X509Certificate2) Try Dim store As New X509Store("teststore", StoreLocation.CurrentUser) store.Open(OpenFlags.ReadWrite) ' The following attempt to add a certificate results in an exception being thrown. store.Add(cert) Return Catch e As SecurityException Console.WriteLine("Security exception thrown when attempting: " + _ CType(e.FirstPermissionThatFailed, System.Security.Permissions.StorePermission).Flags) Return End Try End Sub 'AddToStore
//Deny the permission the ability to add to a store. [StorePermission(SecurityAction.Deny, Flags = StorePermissionFlags.AddToStore)] private static void AddToStore(X509Certificate2 cert) { try { X509Store store = new X509Store("teststore" , StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); // The following attempt to add a certificate results in an exception being thrown. store.Add(cert); return; } catch (SecurityException e) { Console.WriteLine("Security exception thrown when attempting: " + ((StorePermission)e.FirstPermissionThatFailed).Flags); return; } }
//Deny the permission the ability to add to a store. /** @attribute StorePermission(SecurityAction.Deny, Flags = StorePermissionFlags.AddToStore) */ private static void AddToStore(X509Certificate2 cert) { try { X509Store store = new X509Store("teststore" , StoreLocation.CurrentUser); store.Open(OpenFlags.ReadWrite); // The following attempt to add a certificate results in // an exception being thrown. store.Add(cert); return; } catch (System.Security.SecurityException e) { Console.WriteLine("Security exception thrown when attempting: " + ((StorePermission)e.get_FirstPermissionThatFailed()).get_Flags()); return; } } //AddToStore

Windows 98, Windows 2000 SP4, Windows Millennium Edition, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
開発プラットフォームの中には、.NET Framework によってサポートされていないバージョンがあります。サポートされているバージョンについては、「システム要件」を参照してください。


- StorePermissionAttribute コンストラクタのページへのリンク