Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Call to Application_Start after starting application pool in IIS

I would like to know how can I setup the IIS, or the application if needed, for the next requirement: - When the application pool starts in IIS it should call to Application_Start in Global.asax

I was playing around with applicationHost.config getting the following code:

<applicationPools>
        <add name="mySite" autoStart="true" managedRuntimeVersion="v4.0" startMode="AlwaysRunning" />
        <applicationPoolDefaults>
            <processModel identityType="ApplicationPoolIdentity" loadUserProfile="true" setProfileEnvironment="false" />
        </applicationPoolDefaults>
    </applicationPools>

. .

 <site name="mySite" id="2" serverAutoStart="true">
            <application path="/" serviceAutoStartEnabled="true" applicationPool="mySite">
                <virtualDirectory path="/" physicalPath="C:\inetpub\wwwroot\mySite" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="127.0.0.1:8080:" />
            </bindings>
        </site>

So far the Application_Start is called only when a request is done.

like image 832
fiso Avatar asked Dec 11 '12 16:12

fiso


People also ask

How do I Auto Start IIS application pool?

Configuring Auto-Start with IIS ManagerIn the Connections pane, select the Application Pools node, revealing the Application Pools pane in the main view. Select the application pool for which you wish to enable Auto-Start. Locate the Start Mode option under the General group and set it to AlwaysRunning. Click OK.

Why does APP pool stop automatically?

This issue occurs when the IIS application pool Identity Parameter is not set to NetworkService. To resolve this issue, change the Identity parameter to NetworkService in the IIS Manager for Windows Server: Select the Advanced Settings for the DefaultAppPool.

How application pool works in IIS?

Application pools can contain one or more worker processes. Each worker process represents work being done for a Web site, Web application, or Web service. You can create a Web garden by enabling multiple worker processes to run in a single application pool. In IIS 7 and later, each application pool uses one of two .

What is application pool in C#?

For instance, if you wanted every Web Application to execute in a separate process, you simply create an Application Pool for each application. The Application Pool is the heart of a website. Application Pools enable us to isolate our Web Application for better security, reliability and availability.


1 Answers

I just want to supplement what @paul said and agree that I was never able to get what Scott Guthrie said on his blog to fully function. Using:

<applicationPools>

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

</applicationPools>

would get the Application Pool to preload after recycling (as exemplified by seeing the w3wp.exe process reload on recycling the application pool).

But I never was able to get the second part to work:

<sites>

     <site name="MySite" id="1">

          <application path="/" applicationPool="MyAppWorkerProcess" serviceAutoStartEnabled="true" />

     </site>

</sites>

This may be because when using serviceAutoStartEnabled using serviceAutoStartProvider is also neccessary and that was just overkill for me since I simply wanted the Global.asax's Application_Start to be initialized.

Luckily, after reading this post and installing the Application Initialization Module and using this value in the Application configuration instead:

<sites>

     <site name="MySite" id="1">

          <application path="/" applicationPool="MyAppWorkerProcess" preloadEnabled="true" />

     </site>

</sites>

I was able to see that Application_Start is being invoked during initialization. This turns my 10 second initial web service call into a 750 ms initial web service call. Using preloadEnabled is exactly what I needed. I hope it helps others as well.

like image 197
James Eby Avatar answered Nov 15 '22 04:11

James Eby