CAS.CurrentApplicationDirectory Property
Provides information about the System.Net.Security.CAS.CurrentApplicationDirectory property.
Namespace:
System.Net.Security.CAS
Assembly:
System.dll
Syntax:
public static string CurrentApplicationDirectory { get; }
Remarks:
The CurrentApplicationDirectory property is a static property that returns the absolute path to the directory containing the currently executing application. This property is part of the Code Access Security (CAS) model in older .NET Framework versions. It's primarily used to grant specific permissions to code based on its location.
In modern .NET versions, CAS has been largely deprecated in favor of other security models like role-based security and platform-specific security features. However, understanding this property is useful when working with legacy code or environments where CAS is still in use.
This property is read-only and provides a string representing the directory path. It is important to note that the exact behavior and availability of this property might differ slightly between .NET Framework versions.
Example:
using System;
using System.Net.Security;
public class Example
{
public static void Main(string[] args)
{
try
{
// This might throw a security exception if permissions are not granted.
string appDirectory = CAS.CurrentApplicationDirectory;
Console.WriteLine("Current Application Directory: {0}", appDirectory);
}
catch (System.Security.SecurityException ex)
{
Console.WriteLine("Security Exception: {0}", ex.Message);
Console.WriteLine("CAS permissions might be required to access this property.");
}
catch (Exception ex)
{
Console.WriteLine("An error occurred: {0}", ex.Message);
}
}
}
Requirements:
| Platform | Minimum supported version |
|---|---|
| .NET Framework | 4.0 |
| .NET Core/.NET 5+ | Not directly available in the same CAS context. Use AppContext.BaseDirectory or System.IO.Directory.GetCurrentDirectory() for similar functionality. |