In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-09-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly explains "how C # modifies security permissions through permission classes and permission properties". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor take you to learn "how C # modifies security permissions through permission classes and permission properties".
Using System;using System.Security;using System.Security.Permissions;using System.Runtime.InteropServices;class NativeMethods {[DllImport ("msvcrt.dll")] public static extern int puts (string str); [DllImport ("msvcrt.dll")] internal static extern int _ flushall ();} class MainClass {private static void CallUnmanagedCodeWithoutPermission () {SecurityPermission perm = new SecurityPermission (SecurityPermissionFlag.UnmanagedCode); perm.Deny () Try {Console.WriteLine ("Attempting to call unmanaged code without permission."); NativeMethods.puts ("Hello World!"); NativeMethods._flushall (); Console.WriteLine ("Called unmanaged code without permission. Whoops! ");} catch (SecurityException) {Console.WriteLine (" Caught SecurityException attempting to call unmanaged code. ");}} private static void CallUnmanagedCodeWithPermission () {SecurityPermission perm = new SecurityPermission (SecurityPermissionFlag.UnmanagedCode); perm.Assert (); try {Console.WriteLine (" Attempting to call unmanaged code with permission. ") NativeMethods.puts ("Hello World!"); NativeMethods._flushall (); Console.WriteLine ("Called unmanaged code with permission.");} catch (SecurityException) {Console.WriteLine ("Caught SecurityException attempting to call unmanaged code. Whoops! ");}} public static void Main () {SecurityPermission perm = new SecurityPermission (SecurityPermissionFlag.UnmanagedCode); perm.Assert (); CallUnmanagedCodeWithoutPermission (); perm.Deny (); CallUnmanagedCodeWithPermission ();}} using System;using System.Security;using System.Security.Permissions;using System.Runtime.InteropServices Class NativeMethods {[DllImport ("msvcrt.dll")] public static extern int puts (string str); [DllImport ("msvcrt.dll")] internal static extern int _ flushall ();} class MainClass {[SecurityPermission (SecurityAction.Deny, Flags = SecurityPermissionFlag.UnmanagedCode)] private static void CallUnmanagedCodeWithoutPermission () {try {Console.WriteLine ("Attempting to call unmanaged code without permission.") NativeMethods.puts ("Hello World!"); NativeMethods._flushall (); Console.WriteLine ("Called unmanaged code without permission. Whoops! ");} catch (SecurityException) {Console.WriteLine (" Caught SecurityException attempting to call unmanaged code. ");}} [SecurityPermission (SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)] private static void CallUnmanagedCodeWithPermission () {try {Console.WriteLine (" Attempting to call unmanaged code with permission. ") NativeMethods.puts ("Hello World!"); NativeMethods._flushall (); Console.WriteLine ("Called unmanaged code with permission.");} catch (SecurityException) {Console.WriteLine ("Caught SecurityException attempting to call unmanaged code. Whoops! ");}} public static void Main () {SecurityPermission perm = new SecurityPermission (SecurityPermissionFlag.UnmanagedCode); perm.Assert (); CallUnmanagedCodeWithoutPermission (); perm.Deny (); CallUnmanagedCodeWithPermission ();}} using System;using System.Security;using System.Security.Permissions;using System.Runtime.InteropServices Class NativeMethods {[SuppressUnmanagedCodeSecurityAttribute ()] [DllImport ("msvcrt.dll")] internal static extern int puts (string str); [SuppressUnmanagedCodeSecurityAttribute ()] [DllImport ("msvcrt.dll")] internal static extern int _ flushall ();} class MainClass {[SecurityPermission (SecurityAction.Deny, Flags = SecurityPermissionFlag.UnmanagedCode)] private static void CallUnmanagedCodeWithoutPermission () {try {UIPermission uiPermission = new UIPermission (PermissionState.Unrestricted) UiPermission.Demand (); Console.WriteLine ("Attempting to call unmanaged code without UnmanagedCode permission."); NativeMethods.puts ("Hello World!"); NativeMethods._flushall (); Console.WriteLine ("Called unmanaged code without UnmanagedCode permission.");} catch (SecurityException) {Console.WriteLine ("Caught SecurityException attempting to call unmanaged code.") }} [SecurityPermission (SecurityAction.Assert, Flags = SecurityPermissionFlag.UnmanagedCode)] private static void CallUnmanagedCodeWithPermission () {try {Console.WriteLine ("Attempting to call unmanaged code with permission."); NativeMethods.puts ("Hello World!"); NativeMethods._flushall (); Console.WriteLine ("Called unmanaged code with permission.") } catch (SecurityException) {Console.WriteLine ("Caught SecurityException attempting to call unmanaged code. Whoops!);}} public static void Main () {SecurityPermission perm = new SecurityPermission (SecurityPermissionFlag.UnmanagedCode); perm.Assert (); CallUnmanagedCodeWithoutPermission (); perm.Deny (); CallUnmanagedCodeWithPermission ();}} so far, I believe you have a better understanding of "how C # modifies security permissions through permission classes and permission properties". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
The market share of Chrome browser on the desktop has exceeded 70%, and users are complaining about
The world's first 2nm mobile chip: Samsung Exynos 2600 is ready for mass production.According to a r
A US federal judge has ruled that Google can keep its Chrome browser, but it will be prohibited from
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
About us Contact us Product review car news thenatureplanet
More Form oMedia: AutoTimes. Bestcoffee. SL News. Jarebook. Coffee Hunters. Sundaily. Modezone. NNB. Coffee. Game News. FrontStreet. GGAMEN
© 2024 shulou.com SLNews company. All rights reserved.