IIS 7.5 and “Always Running” Web Applications

Damir Dobric Posts

Next talks:

 

    

Follow me on Twitter: #ddobric



 

 

Archives

IIS 7.5 which is ships with Windows Server 2008 R2 and Windows 7 provides a new feature for Web Applications. This feature allows one to install a Web Application which is not initialized after receiving of the first request started. Instead such application is started immediately after it is configured to run in this mode which is called “Always Running”. Always Running is more an attribute of the application pool than of application. The same feature is supported by ASP.NET 4.0. In ASP.NET 4.0 context it is simply called “Auto-Start”.

To setup the pool set the attribute startMode to AlwaysRunning of the IIS config file C:\Windows\System32\inetsrv\config\applicationHost.config:

<applicationPools>
    <add name="MyAppWorkerProcess" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />
</applicationPools>

 

Immediately after saving of the changed config-file the new process W3WP.EXE will be started.

If you want to specify which application will be auto=startable see following example:

<sites> 
     <site name="SomeSite" id="1"> 
          <application path="/" serviceAutoStartEnabled="true" />
     </site>
</sites>

 

Additionally you can even implement some kind of reloading functionality called Auto Start Provider. To do that implement the interface IProcessHostPreloadClient .
While the application is starting one specific method of that provider will be called to do whatever on start-up. While the application is starting app, no request will be executed by IIS.

public class MyStartUpCode : System.Web.Hosting.IProcessHostPreloadClient
{

public void Preload(string[] parameters) 
{
    . . .

  }

}

 

To register the custom Auto Start Provider code:

<serviceAutoStartProviders>
     <add name="MyAutoStartProvider" type="MyStartUpCode, TheNameOfMyAssembly" />
</serviceAutoStartProviders>

To activate it do following:

<sites> 
     <site name="SomeSite" id="1"> 
          <application path="/" serviceAutoStartEnabled="true" serviceAutoStartProvider=”MyAutoStartProvider” />
     </site>
</sites>

Posted Oct 11 2009, 10:19 PM by Damir Dobric
Filed under: , , ,

Comments

Damir Dobric wrote re: IIS 7.5 and “Always Running” Web Applications
on 12-27-2009 15:02

Note that is some cases w3wp.exe will not start automatically as described in the post above.

W3wp.exe is launched if there is at least one application associated with the pool.

Please also note that any change in the applicationHost.config file part related to certain application pool will cause all applications which use that pool,

to reconfigure to use the default pool called “ASP.NET V40”.

Damir Dobric Posts wrote Host WCF Services with Service Bus Endpoints in IIS and Windows Server AppFabric
on 08-28-2010 15:19

If you know how *RelyBindings of Service Bus works or have at least an idea how they could work, it is

TomN wrote re: IIS 7.5 and “Always Running” Web Applications
on 01-16-2012 9:42

I want to autostart my application so i created a class whitin my application:

namespace Administration.Presentation

{

   public class StartUp : System.Web.Hosting.IProcessHostPreloadClient

   {

       public void Preload(string[] parameters)

       {

           StreamWriter fs = new StreamWriter(@"c:\temp\log.txt", true);

           fs.WriteLine(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + " started ");

           fs.Dispose();

       }

   }

}

The provider and site node in my iis config:

<serviceAutoStartProviders>

       <add name="AutoStartProvider" type="StartUp ,Administration.Presentation" />        

</serviceAutoStartProviders>

<site name="Development" id="9" serverAutoStart="true">

        <application serviceAutoStartEnabled="true" serviceAutoStartProvider="AutoStartProvider"  path="/apollo" applicationPool="Dev">

        </application>

</site>

but when starting iis i get an error in my eventviewer:

There was an error during processing of the managed application service auto-start for configuration path: 'MACHINE/WEBROOT/APPHOST Development'. The error message returned is: 'An error occurred while executing Preload method.

Exception: System.InvalidOperationException

Message: An error occurred while trying to create preload provider 'StartUp , Administration.Presentation'.

Exception: System.TypeLoadException

Message: Could not load type 'StartUp' from assembly 'Administration.Presentation'.

StackTrace:    at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMarkHandle stackMark, Boolean loadTypeFromPartialName, ObjectHandleOnStack type)

  at System.RuntimeTypeHandle.GetTypeByName(String name, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark, Boolean loadTypeFromPartialName)

  at System.RuntimeType.GetType(String typeName, Boolean throwOnError, Boolean ignoreCase, Boolean reflectionOnly, StackCrawlMark& stackMark)

  at System.Type.GetType(String typeName, Boolean throwOnError)

  at System.Web.Hosting.PreloadHost.CreateIProcessHostPreloadClientInstanceAndCallPreload(String preloadObjTypeName, String[] paramsForStartupObj)

StackTrace:    at System.Web.Hosting.PreloadHost.CreateIProcessHostPreloadClientInstanceAndCallPreload(String preloadObjTypeName, String[] paramsForStartupObj)

  at System.Web.Hosting.PreloadHost.CreateIProcessHostPreloadClientInstanceAndCallPreload(String preloadObjTypeName, String[] paramsForStartupObj)

  at System.Web.Hosting.ProcessHost.PreloadApplicationIfRequired(String appId, IApplicationHost appHostParameter, HostingEnvironmentParameters hostingParameters, LockableAppDomainContext ac)'.  The worker process will be marked unhealthy and be shutdown.  The data field contains the error code.

what did i do wrong?

Damir Dobric wrote re: IIS 7.5 and “Always Running” Web Applications
on 01-16-2012 22:29

Hi Top, this post is related to AppFabric auto-start feature. I would recomment it, because exactlyy such kind og issues will not happen.

Second, you should define fully qualified type name (AssemblyQuelifiedName).

<add name="AutoStartProvider" type="HereYouMiss Assembly, Namespace etc. StartUp ,Administration.Presentation" />    

John Krikos wrote re: IIS 7.5 and “Always Running” Web Applications
on 04-23-2012 19:14

Please explain better the following:

<add name="AutoStartProvider" type="HereYouMiss Assembly, Namespace etc. StartUp ,Administration.Presentation" />

--

Thanks.

Vijay wrote re: IIS 7.5 and “Always Running” Web Applications
on 06-29-2012 20:58

Is this feature really working? I setup same configuration in Win 7, IIS 7.5 for a WCF service hosted in IIS. I need to call particular function to cache some heavy data.

Damir wrote re: IIS 7.5 and “Always Running” Web Applications
on 07-09-2012 8:55

The feature works :). We have it running in several projects.

Here you have few internal undocumented details which might be helpful: developers.de/.../when-is-the-wcf-service-auto-started.aspx

developers.de is a .Net Community Blog powered by daenet GmbH.