What is Code-Access security?
Code access security is a mechanism that helps limit the access to the code by protecting the resources. It defines permissions which tell about the rights to access various. It also imposes restrictions on code at run time.
Code:
using System;
namespace ConsoleReadRegistry
{
class SecurityClass
{
[STAThread]
static void Main(string[] args)
{
Microsoft.Win32.RegistryKey regKey;
try
{
regKey =Microsoft.Win32.Registry.LocalMachine.OpenSubKey
("Software\\Microsoft\\.NetFramework",false);
string[] skNames = regKey.GetSubKeyNames();
for (int i=0;i<skNames.Length;++i)
{
Console.WriteLine("Registry Key: {0}", skNames[i]);
}
regKey.Close();
}
catch(System.Security.SecurityException e)
{
Console.WriteLine("Security Exception Encountered: {0}", e.Message);
}
}
}
}