Explain 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.
- It enforces the varying levels of trust on code, which minimizes the amount of code that must be fully trusted in order to run.
- It can reduce the likelihood that your code can be misused by malicious or error-filled code.
- Code access security reduces your liability because you can specify the set of operations .
- It can also help to minimize the damage that can result from security vulnerabilities in your code.
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);
}
}
}
}