This article has been excerpted from book "The Complete Visual C# Programmer's Guide" from the Authors of C# Corner.

In .NET, each application runs in an application domain under the control of a host. The host creates the application domain and loads assemblies into it. The host has access to information about the code via evidence. This information can include the zone in which the code originates or the digital signatures of the assemblies in the application domain. The System.AppDomain class provides the application domain functionality and is used by hosts. A host can be trusted if it provides the CLR with all the evidence the security policy requires.

There are several types of application hosts:

Listing 22.4 executes the managed application MyApp.exe, with specific evidence inside the Internet security zone, in which code has minimal access to local resources.

Listing 22.4: Running an Application with a Specific Evidence and Zone

String myApplication = @"C:\MyApp.exe";
String[] argsToApp = null;
String myURL = @"http://www.mindcracker.com";
SecurityZone myZone = SecurityZone.Internet;
Evidence myEvidence = new Evidence();
myEvidence.AddHost(new Zone(myZone));
myEvidence.AddHost(new Url(myURL));
AppDomain app = AppDomain.CreateDomain(myApplication, myEvidence);
app.ExecuteAssembly(myApplication, myEvidence, argsToApp);

Conclusion

Hope this article would have helped you in understanding Application Domains in C#. See other articles on the website on .NET and C#.

visual C-sharp.jpg
The Complete Visual C# Programmer's Guide covers most of the major components that make up C# and the .net environment. The book is geared toward the intermediate programmer, but contains enough material to satisfy the advanced developer.