سؤال

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.

هل كانت مفيدة؟

المحلول

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.

مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top