What is the App Domain Concept in ASP.NET? | Eklavya Online

What is the App Domain Concept in ASP.NET?

ASP.NET introduces the concept of an Application Domain which is known as AppDomain for short. It can be considered as a lightweight process which is both a container and boundary. The .NET runtime uses an AppDomain as a container for code and data, just like the operating system uses a process as a container for code and data. As the operating system uses a process to isolate misbehaving code, the .NET runtime uses an AppDomain to isolate code inside a secure boundary.

The CLR can allow the multiple .NET applications to run in a single AppDomain. Mulitple Appdomains can exist in Win32 process.

How to create AppDomain

AppDomains are created using the CreateDomain method. AppDomain instances are used to load and execute assemblies (Assembly). When an AppDomain is no longer in use, it can be unloaded.

  1. public class MyAppDomain: MarshalByRefObject
  2. {
  3. public string GetInfo()
  4. {
  5. return AppDomain.CurrentDomain.FriendlyName;
  6. }
  7. }
  8. public class MyApp
  9. {
  10. public static void Main()
  11. {
  12. AppDomain apd = AppDomain.CreateDomain(“Rajendrs Domain”);
  13. MyAppDomain apdinfo = (MyAppDomain) apd.CreateInstanceAndUnwrap(Assembly.GetCallingAssembly()
  14. .GetName()
  15. .Name, “MyAppDomain”);
  16. Console.WriteLine(“Application Name = ” + apdinfo.GetInfo());
  17. }
  18. }