简体   繁体   English

在IIS中启动应用程序池后调用Application_Start

[英]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 我想知道如何为下一个要求设置IIS或应用程序(如果需要): - 当应用程序池在IIS中启动时,它应该调用Global.asax中的Application_Start

I was playing around with applicationHost.config getting the following code: 我正在使用applicationHost.config获取以下代码:

<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. 到目前为止,仅在请求完成时才调用Application_Start。

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. 我只想补充@paul所说的内容,并同意我无法得到Scott Guthrie 在他的博客所说的全部功能。 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). 将回收后的应用程序池预加载(例如,通过回收应用程序池时看到w3wp.exe进程重新加载)。

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. 这可能是因为当使用serviceAutoStartEnabled时使用serviceAutoStartProvider也是必要的,这对我来说太过分了,因为我只是想要初始化Global.asax的Application_Start

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. 我能够看到在初始化期间正在调用Application_Start This turns my 10 second initial web service call into a 750 ms initial web service call. 这将我的10秒初始Web服务调用转换为750毫秒的初始Web服务调用。 Using preloadEnabled is exactly what I needed. 使用preloadEnabled正是我所需要的。 I hope it helps others as well. 我希望它也有助于其他人。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM