Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

IIS AppDomain instantiation

Tags:

iis

appdomain

I have a web site and a web service under the same virtual directory and some of the web pages call the web service.

When the web service is called, does IIS create a new AppDomain or does it run the web service in the same AppDomain?

Is there a setting for this? On one of my machine it appears to create a new AppDomain. Does changing application pool mode from Integrated vs Classic affect this?

like image 682
Chris Avatar asked Aug 29 '11 13:08

Chris


People also ask

What is AppDomain in IIS?

An AppDomain is a . NET term. (In IIS7, AppDomains play a larger role within IIS, but for the most part it's an ASP.NET term) An AppDomain contains InProc session state (the default session state mode). So if an AppDomain is killed/recycled, all of your session state information will be lost.

What is the use of AppDomain in C#?

The AppDomain class implements a set of events that enable applications to respond when an assembly is loaded, when an application domain will be unloaded, or when an unhandled exception is thrown.


1 Answers

IIS Application Pools run a single worker process (by default). Within that worker process, an AppDomain is created for each IIS Application (website). As far as I am aware, any code executing within that IIS Application will run in the same AppDomain (unless of course you are creating your own child application domains in code yourself). You can adjust the number of worker processes per website, but realistically only do this if you are finding you are having performance issues (that cannot be resolved by segregating the application pools). If you run multiple application domains per website, code running in those separate application domains cannot share state (e.g. InProc session), and can only communicate through serialisation - not ideal.

In regards to ASP.NET and WCF; when hosted in IIS they by default run in side-by-side mode, within the same AppDomain, this allows them to share state, but WCF requests are not processed by the ASP.NET runtime, instead calls to WCF services are intercepted and processed by the WCF runtime. (Although calls to .svc files are still routed through ASP.NET initially). In side-by-side mode, WCF calls do not obey configuration, security, impersonation etc. that you may have configured for your ASP.NET website.

WCF on IIS can also be run in ASP.NET Compatibility mode, in which the WCF implementation is managed by a http handler, and thus are processed by the ASP.NET pipeline also. If you would consider that your services need only HTTP support, you could consider hosting the service in compatability mode to gain access to the power and flexibility of the ASP.NET pipeline.

In regards to Integrated and Classic pipeline mode, in Intergrated mode, ASP.NET is run by the w3wp.exe as an integrated part of the IIS processing pipeline. This means that anything using custom handlers, etc, that you may have plugged into the pipeline (even when serving non-ASP.NET content, e.g. PHP), will be loaded and executed in the same AppDomain.

In Classic mode, ASP.NET is run in its owner worker process, aspnet_wp.exe, and is connected to the IIS processing pipeline as an ISAPI filter. I believe the same mechanics around AppDomain usage applies here also.

like image 138
Matthew Abbott Avatar answered Sep 28 '22 10:09

Matthew Abbott