简体   繁体   English

IIS网站无法自动启动

[英]IIS Website not autostarting

I'm struggling to get my IIS site to autostart. 我正在努力使我的IIS站点能够自动启动。 I'm using Quartz.Net inside it for nightly tasks but they aren't running because IIS disposes of it before they can run. 我在其中使用Quartz.Net来执行夜间任务,但它们没有运行,因为IIS在运行它们之前就将其处理掉。 I've attempted to set it to autostart and stay runninig by doing the following (using these instructions ): 我尝试通过执行以下操作(使用这些说明 )将其设置为自动启动并保持运行状态:

ApplicationHost.Config: ApplicationHost.Config:

<configuration>
<configSections>

...

<system.applicationHost>

    <applicationPools>
        <add name="DefaultAppPool" enable32BitAppOnWin64="true" managedRuntimeVersion="v4.0" />
        <add name="ASP.NET v4.0" enable32BitAppOnWin64="false" managedRuntimeVersion="v4.0" />
        <add name="ASP.NET v4.0 Classic" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
        <add name="Classic .NET AppPool" managedRuntimeVersion="v4.0" managedPipelineMode="Classic" />
       ...
        <add name="AUTOSTARTSITE" autoStart="true" managedPipelineMode="Integrated" startMode="AlwaysRunning">
            <processModel identityType="NetworkService" />
        </add>
        <applicationPoolDefaults managedRuntimeVersion="v4.0">
            <processModel identityType="NetworkService" />
        </applicationPoolDefaults>
    </applicationPools>

   ...

    <sites>
        <site name="AUTOSTARTSITE" id="10" serverAutoStart="true" serviceAutoStartEnabled="true" serviceAutoStartProvider="StartUpCode">
            <application path="/" applicationPool="AUTOSTARTSITE">
                <virtualDirectory path="/" physicalPath="E:\websites\AUTOSTARTSITE" />
            </application>
            <bindings>
                <binding protocol="http" bindingInformation="*:80:AUTOSTARTSITE.com" />
            </bindings>
            <traceFailedRequestsLogging enabled="true" />
            <logFile directory="%SystemDrive%\inetpub\logs\LogFiles" />
        </site>
        <siteDefaults>
            <logFile logFormat="W3C" directory="%SystemDrive%\inetpub\logs\LogFiles" />
            <traceFailedRequestsLogging directory="%SystemDrive%\inetpub\logs\FailedReqLogFiles" />
        </siteDefaults>
        <applicationDefaults applicationPool="DefaultAppPool" />
        <virtualDirectoryDefaults allowSubDirConfig="true" />
    </sites>

    <serviceAutoStartProviders>

         <add name="StartUpCode" type="StartUpCode, AUTOSTARTSITE" />

    </serviceAutoStartProviders>

    <webLimits />

</system.applicationHost>

... ...

And here is my startup code. 这是我的启动代码。 I didn't put in a namespace, and I have it log that it runs so I can confirm the process is working. 我没有放入名称空间,并且将其运行记录在日志中,以便可以确认该过程是否正常运行。 Unfortunatly, it does not run. 不幸的是,它无法运行。

StartUpCode: StartUpCode:

public class StartUpCode : System.Web.Hosting.IProcessHostPreloadClient
{
    readonly log4net.ILog logger = log4net.LogManager.GetLogger(System.Reflection.MethodBase.GetCurrentMethod().DeclaringType);

    public void Preload(string[] parameters)
    {
        SetupJobs();
        logger.Info("Quartz Jobs Setup Successfully");
    }
}

Despite these changes, it runs the same as before. 尽管有这些更改,它的运行与以前相同。 Am I missing something obvious? 我是否缺少明显的东西?

I think for all this stuff to work properly you need to install Application Initialization feature for IIS: 我认为要使所有这些东西正常工作,您需要为IIS安装应用程序初始化功能:

在此处输入图片说明

You can find more details on how it is supposed to work here . 您可以在此处找到有关它应该如何工作的更多详细信息。

We found generally that no matter what sometimes it just does not work. 我们总的来说发现,不管有时候它什么都不起作用。 So there are really 2 solutions here: 因此,这里确实有两种解决方案:

  1. Do not run scheduler in IIS, use Windows Service or scheduled task maybe 不要在IIS中运行计划程序,使用Windows Service或计划的任务
  2. Write a pinger that will again be either windows service or scheduled task. 编写一个pinger,它将再次成为Windows服务或计划任务。 It's probably one line with powershell to issue a GET to your site. 使用powershell向您的站点发布GET可能是一句话。 That can run again as a service or scheduled task. 可以再次作为服务或计划任务运行。

I would definitely prefer option 1 to not depend on IIS life-cycle for critical scheduling operations. 我绝对希望选项1不依赖IIS生命周期进行关键的调度操作。 Even though this approach with IIS hosting is still quite popular and we use it there is just too many problems with it in my experience. 尽管这种使用IIS托管的方法仍然非常流行,并且我们使用它,但根据我的经验,仍然存在太多问题。

We too had same issue using Quartz the reason was the IIS pool was shutting down after some idle time.So we had to prevent it from shutting down and it worked for Us. 我们在使用Quartz时也遇到了同样的问题,原因是IIS池在闲置一段时间后关闭了,因此我们必须防止它关闭并为我们工作。

在此处输入图片说明

Find more details here 在这里找到更多详细信息

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

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